Hey guys, been looking how to make a fat jar from ...
# gradle
a
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
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
ya Ive tried that but somehow it didn’t work
t
Yes, check shadow plugin
a
when I run the jar produced by shadowJar it says mainclass not found 😛
my build.gradle lookis like this
Copy code
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
If Gatling is a file with a main function on file-level (e.g. no class), try
io.gatling.app.GatlingKt
👎 1
1
g
How do you build it?
a
im using gatling plugin as it is described here
Without shadow I was trying this way
Copy code
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
Copy code
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
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
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
925 Views