Title
a

André Martins

04/07/2022, 4:15 PM
Hey guys, been looking how to make a fat jar from kotlin, was looking at this although its not working (im using gradle 7+) any suggestions?
e

Emil Kantis

04/07/2022, 4:18 PM
I’ve been using Shadow for a few years to do this. Ktor docs also suggests using shadow. https://ktor.io/docs/fatjar.html
a

André Martins

04/07/2022, 4:19 PM
ya Ive tried that but somehow it didn’t work
t

tapchicoma

04/07/2022, 4:20 PM
Yes, check shadow plugin
a

André Martins

04/07/2022, 4:24 PM
when I run the jar produced by shadowJar it says mainclass not found 😛
my build.gradle lookis like this
plugins {
    id 'application'
    id 'kotlin'
    id 'io.gatling.gradle'
    id 'com.github.johnrengelman.shadow'
}

application {
    mainClass = 'io.gatling.app.Gatling'
}

shadowJar {
    manifest {
        attributes 'Main-Class': 'io.gatling.app.Gatling'
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
}
e

Emil Kantis

04/07/2022, 4:25 PM
If Gatling is a file with a main function on file-level (e.g. no class), try
io.gatling.app.GatlingKt
👎 1
1
g

gildor

04/07/2022, 4:25 PM
How do you build it?
a

André Martins

04/07/2022, 4:27 PM
im using gatling plugin as it is described here
Without shadow I was trying this way
plugins {
    id 'application'
    id 'kotlin'
    id 'io.gatling.gradle'
}

task fatJar(type: Jar) {
    manifest {
        attributes 'Main-Class': 'io.gatling.app.Gatling'
    }
    from { configurations.implementation.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
}
But i get this error
Resolving dependency configuration 'implementation' is not allowed as it is defined as 'canBeResolved=false'.
  Instead, a resolvable ('canBeResolved=true') dependency configuration that extends 'implementation' should be resolved.
I suspect it is due to how the gatling plugin gets the dependencies
v

Vampire

04/07/2022, 4:48 PM
My recommendation would be to not buid a fat jar actually. Fat jars basically only have drawbacks and with Gradle it is super easy to build a proper distribution including a start script you can simply call to execute your project. You are even already applying and configuring the
application
plugin, you just have to use the
distZip
or
distTar
result and you are good to go. See https://fatjar.net for various quotes.
👍 3
e

ephemient

04/07/2022, 4:51 PM
it looks like Gatling sets up a separate source set and run configuration, not main, so it's expected that io.gatling.app.Gatling isn't in the main jar or its dependencies