0

Apologies if this question has already been asked, the barrier to entry with Gradle seems very high and I'm not sure what to search for.

My Kotlin project depends on various artifacts to offer the Kotlin runtime, such as kotlin-stdlib-jdk8-1.2.60.jar, for example.

The Kotlin library is being loaded by a raw Java application.

I need to inform the Kotlin library JAR that I am distributing to look in the /kotlin directory (relative to the directory in which it will be placed) for its runtime libraries and any other dependencies. From what I have seen, I need to add this to the runtimeClasspath or similar but I am unsure how.

Thanks for any help.

  • 1
    Are you checking the jars in to your project? Most projects get their dependencies from a remote repository (such as Maven Central), which is very simple to configure and manage. – Todd Aug 04 '18 at 12:18
  • are you familiar with maven? Gradle would be the same thing basically. – sschrass Aug 04 '18 at 12:21
  • I have configured build.gradle to download and use the Kotlin stdlib libraries from Maven Central, yes - but when I distribute the JAR, the Kotlin libs will be stored locally in a `kotlin` folder relative to the library. Is this not a good approach? Otherwise I would depend on the client using Gradle. – Benjamin Crawford Ctrl-Alt-Tut Aug 04 '18 at 12:22
  • Not a good approach! Kotlin is a JVM-Language, in order to run your application, one would need an JVM. Kotlin is translated into byte code and executed in the JVM like regular Java applications afaik. Your user has to install the JVM for his hardware arch. Therefore nothing you should ship with your app. – sschrass Aug 04 '18 at 12:30
  • @sschrass Huh? I said in the question that the library is going to be loaded by a raw Java application, so I know _for sure_ that the client has a fully working and configured JVM as its already running the application - my Kotlin plugin is going to be loaded at runtime. The problem is simply one of configuration so that my lib knows where to look. – Benjamin Crawford Ctrl-Alt-Tut Aug 04 '18 at 12:36
  • oh! Sorry, I totally got you wrong! But I am still confessed you don't need this. See https://stackoverflow.com/questions/30565036/why-kotlin-needs-to-bundle-its-runtime-after-compiled (2nd answer). – sschrass Aug 04 '18 at 12:43

1 Answers1

0

If your jars are public for the world, you would only need to declare them in your build.gradle (module, not project) like

implementation 'com.squareup.retrofit2:converter-scalars:2.3.0'

Gradle would pick them up, no need to store them in your project.

sschrass
  • 7,014
  • 6
  • 43
  • 62
  • Thanks, but Gradle isn't going to be used on the client end, so it won't be able to just pick them up. I effectively want to create a fat jar, but instead of bundling all the files into a single jar (not possible in my case, as there are duplicate files etc.), I'm distributing them as individual artifacts. I want the Kotlin runtime to be stored in a `/kotlin` folder relative to the library. – Benjamin Crawford Ctrl-Alt-Tut Aug 04 '18 at 12:32
  • I still think there is nothing like a Kotlin runtime. Its more like a library containing support classes, that gets translated into byte code, that gets executed in the JVM (JRE). The byte code would be the same (I assume) as if its were written in java. – sschrass Aug 04 '18 at 12:47