Build JAR Gradle external library



I’m a total newbie to Kotlin and Java: Sorry :wink:

I have to build a little program using a proprietary library. This library is a jar file.

I use IntelliJ and simply hit Ctrl + R to run this program. This way I got a working program. Now I want to use this program as binary inside a docker / server / whatever. And I thought i want to build a JAR. My search revealed two solutions “Build Artifacts” und gradle.
With Build Artifcats I get a jar file, but this jar allways dies with errors.

Then I tried using gradle, starting a new project (Project Wizard, Gradle, Kotlin). Having everything in one kt source file it seemed to work. gradle build created a distrubiton folder with a tar and a zip and binaries inside.
I seperated some functionality into a package. Again using Ctrl + R, everything worked (with man adding the library-jar file at multiple places (Project Structure->Dependencies)

But my gradle build allways failes with: Unresolved reference: originating in the package file, not the “main” file.

I really don’t understand the interaction of IntelliJ, Gradle, the build.gradle file and everything.

Is there any good basic tutorial covering my usecase?

Thanks a lot!


Gradle will, by default, bundle only the current project files into the result JAR; it’s dependencies (including Kotlin!) should be declared and would be pulled separately by another Gradle project that has yours as a dependency.

What you want is a fat JAR, one that contains all the dependencies. See e.g. here for how to build one.