I'm trying to slim down a cli tool (a fat jar), wh...
# gradle
r
I'm trying to slim down a cli tool (a fat jar), which was about 200kb and now after adding some network features grew up to 16MB. What I have noticed is, that my older jar contained just my own classes, but the new jar had a lot classes with the packages kotlin and kotlinx and I'm wondering why they are there
o
what libraries are you using
and if you're using kotlin stdlib (which is likely), then it'd be surprising if those weren't there in your fat jar before (it shouldn't have run!)
r
Copy code
org.jetbrains.kotlin:kotlin-stdlib-jdk8
khttp
io.ktor:ktor-client-okhttp
io.ktor:ktor-client-json
io.ktor:ktor-client-gson
com.google.apis:google-api-services-oauth2
that should be the most relevant
o
yes, stdlib & ktor will pull in kotlin packages, and likely kotlinx too since a lot of ktor interfaces with coroutines
if you need to trim those libraries to just what you use, I recommend using https://github.com/johnrengelman/shadow 's minimize feature
r
okay I see, but I veryfied that the old jar does not contain any kotlin packages
o
if you still relied on kotlin stdlib, then as I said, it was an improperly built fat jar
r
interessing, but it worked as I expected
o
do you mind uploading it here?
r
o
that looks like a 5mb file, with the kotlin/kotlinx/etc. packages
r
ah shit you are right, what had I in mind?
💩 1
o
it's possible you were looking at the application plugin's distribution
r
it looks like
o
in which case, each jar is stored separately in
lib
r
I mixed them up
g
Shadow minification is pretty basic. Only Proguard will shrink your jar properly, keep only classes and methods which is use
Still it make sense to enable at least shadow plugin minification,
o
tbh, I still have no idea how to use proguard outside of an android project or I would do so
g
It's not so straight forward as with Android, but not so hard, they have Gradle plugin, but it doesn't help a lot. Essentially you just specify config path with at least obe entry point (your main method probably) and some additional configs, but jar input and output is configured manually, check their official example