Carter
03/16/2021, 8:21 PMcom.github.johnrengelman.shadow
I’m trying to create a fat JAR from various kotlin modules and my attempts to exclude transitive dependencies don’t seem to be working. My output JAR is truly fat at 820mb.
I’ve tried doing this, which is what I think I need:
dependencies {
implementation(project(":brainLib")) {
transitive = false
}
}
But I get the error:
Could not determine the dependencies of task ':brainLib:compileKotlinJvm'.
> Could not resolve all dependencies for configuration ':brainLib:jvmCompileClasspath'.
> Cannot change dependencies of dependency configuration ':brainLib:commonMainApi' after it has been included in dependency resolution.
I also tried this, which is supposed to be like a “keep” rule in proguard, but that didn’t work either. (I think because the huge dependencies are transitive under brainLib).
shadowJar {
minimize {
exclude(project(":brainLib"))
}
}
Are there other suggestions as to what I could try?tapchicoma
03/16/2021, 8:29 PMshadowJar {
dependencies {
exclude(project(':api'))
}
}
Also have you considered adding :brainLib as compileOnly dependency?Carter
03/16/2021, 8:30 PMCarter
03/16/2021, 8:31 PMCarter
03/16/2021, 8:31 PMtapchicoma
03/16/2021, 8:36 PM:brainLib with transitive = false and add this custom configuration to shadow jar task:
shadowJar {
configurations = [project.configurations.compile]
}tapchicoma
03/16/2021, 8:37 PM:brainLib dependency to compileOnlyCarter
03/16/2021, 8:41 PMcompileOnly sort of breaks the usage with the rest of the application. I could make it work, but it would be a royal pain since I’d have to duplicate the transitive dependencies under my test configuration and by the downstream gradle module consumer of app
brainLib is consumed in my gradle project by an app project, so the transitive dependencies are important there.
brainLib depends on dl4j, kotlin-dl, and smile but hides their implementations from downstream consumers for the most part as an implementation detail.
What I’m really trying to do now is additionally create a fat jar I can upload to Datalore for some analysis as part of debugging some of the ML models.
Kotlin for Jupyer notebooks supports dl4j, kotlin-dl, and smile as libraries so they don’t need to be bundled into the fat JAR.Carter
03/16/2021, 8:43 PMdependencies {
implementation(project(":brainLib")) {
transitive = false
}
}Carter
03/16/2021, 8:44 PMtapchicoma
03/16/2021, 8:44 PM:brainLib depends on are not available for :brainLib consumer - meaning some public types may not be available required for compilation.Carter
03/16/2021, 8:46 PMcompile dependencies, then consuming that configuration only in my shadow module might be a workaround.Carter
03/16/2021, 8:47 PMtapchicoma
03/16/2021, 8:48 PM:brainLib with transitive depdendencies second time to implementation . No idea if it will work 🤔tapchicoma
03/16/2021, 8:50 PMimplamentation and testImplementation in your case) will extend from it.Carter
03/16/2021, 8:59 PMCarter
03/18/2021, 12:25 PMplugins {
id("java")
id("com.github.johnrengelman.shadow")
}
configurations {
"implementation" {
exclude("org.jetbrains.kotlin")
exclude("org.jetbrains.kotlinx")
exclude("org.jetbrains.exposed")
...
}
}
dependencies {
implementation(project(":brainLib"))
implementation(project(":dbLib"))
...
}tapchicoma
03/18/2021, 12:27 PMCarter
03/18/2021, 12:27 PMCarter
03/18/2021, 12:28 PMfatLib just declares dependencies and has no code of its own. So it is consuming the outputs of those other libraries with my code, then dropping the third party dependencies.Carter
03/18/2021, 12:30 PM%use exposed, serialization, deeplearning4jtapchicoma
03/18/2021, 12:41 PM