Polpetta / jkk

A git-like cli for Jenkins written in Kotlin 🤵 🔥
GNU General Public License v3.0
0 stars 1 forks source link

Use shadow to remove unused classes from jar #81

Open solonovamax opened 2 years ago

solonovamax commented 2 years ago

Use the shadow plugin to remove unused classes from the jar via minimization.

For example (Kotlin gradle DSL):

tasks {
    withType<ShadowJar>().configureEach {
        archiveClassifier.set("standalone")

        mergeServiceFiles()
        minimize {
            exclude { // exclude any modules you need to exclude from minimization here
                it.moduleName == "something"
            }
        }
    }

    withType<Jar>().configureEach {
        from(rootProject.file("LICENSE"))
        manifest {
            attributes(
                    "Main-Class" to "it.polpetta.Cli",
                    "Built-By" to System.getProperty("user.name"),
                    "Built-Date" to Date(),
                    "Built-Jdk" to System.getProperty("java.version"),
                    "Implementation-Title" to "JKK: A git-like cli for Jenkins written in Kotlin",
                    "Implementation-Version" to project.version.toString(),
                    "Add-Opens" to "java.base/java.lang"
                      )
        }
    }
}

This will make your jar significantly lighter

solonovamax commented 2 years ago

From testing, minimization drops the size from 23Mb (with the updates I made on my fork) to 14Mb

solonovamax commented 2 years ago

I'll PR eventually