Build: Introduce flag for disabling jar post processing
proguard, relocation, etc.
This commit is contained in:
@@ -35,7 +35,6 @@ val core = "$rootDir/core"
|
||||
val relocatedCoreSrc = "$buildDir/core-relocated"
|
||||
val libsDir = property("libsDir")
|
||||
|
||||
|
||||
val proguardDeps by configurations.creating
|
||||
val proguardAdditionalInJars by configurations.creating
|
||||
|
||||
@@ -109,23 +108,25 @@ class KotlinModuleShadowTransformer(private val logger: Logger) : Transformer {
|
||||
}
|
||||
|
||||
val reflectShadowJar by task<ShadowJar> {
|
||||
classifier = "shadow"
|
||||
version = null
|
||||
archiveClassifier.set("shadow")
|
||||
configurations = listOf(embedded)
|
||||
|
||||
callGroovy("manifestAttributes", manifest, project, "Main" /*true*/)
|
||||
|
||||
exclude("**/*.proto")
|
||||
|
||||
transform(KotlinModuleShadowTransformer(logger))
|
||||
|
||||
configurations = listOf(embedded)
|
||||
relocate("org.jetbrains.kotlin", "kotlin.reflect.jvm.internal.impl")
|
||||
relocate("javax.inject", "kotlin.reflect.jvm.internal.impl.javax.inject")
|
||||
mergeServiceFiles()
|
||||
|
||||
if (kotlinBuildProperties.relocation) {
|
||||
transform(KotlinModuleShadowTransformer(logger))
|
||||
relocate("org.jetbrains.kotlin", "kotlin.reflect.jvm.internal.impl")
|
||||
relocate("javax.inject", "kotlin.reflect.jvm.internal.impl.javax.inject")
|
||||
}
|
||||
}
|
||||
|
||||
val stripMetadata by tasks.creating {
|
||||
dependsOn("reflectShadowJar")
|
||||
val inputJar = reflectShadowJar.archivePath
|
||||
dependsOn(reflectShadowJar)
|
||||
val inputJar = reflectShadowJar.outputs.files.singleFile
|
||||
val outputJar = File("$libsDir/kotlin-reflect-stripped.jar")
|
||||
inputs.file(inputJar)
|
||||
outputs.file(outputJar)
|
||||
@@ -189,14 +190,18 @@ addArtifact("archives", sourcesJar)
|
||||
addArtifact("sources", sourcesJar)
|
||||
|
||||
val result by task<Jar> {
|
||||
dependsOn(proguard)
|
||||
from(zipTree(file(proguardOutput)))
|
||||
val task = if (kotlinBuildProperties.proguard) proguard else reflectShadowJar
|
||||
dependsOn(task)
|
||||
from {
|
||||
zipTree(task.outputs.files.singleFile)
|
||||
}
|
||||
|
||||
callGroovy("manifestAttributes", manifest, project, "Main")
|
||||
}
|
||||
|
||||
val modularJar by task<Jar> {
|
||||
dependsOn(proguard)
|
||||
classifier = "modular"
|
||||
archiveClassifier.set("modular")
|
||||
from(zipTree(file(proguardOutput)))
|
||||
from(zipTree(reflectShadowJar.archivePath)) {
|
||||
include("META-INF/versions/**")
|
||||
|
||||
@@ -8,11 +8,6 @@ plugins {
|
||||
id("jps-compatible")
|
||||
}
|
||||
|
||||
// You can run Gradle with "-Pkotlin.build.proguard=true" to enable ProGuard run on the jar (on TeamCity, ProGuard always runs)
|
||||
val shrink =
|
||||
findProperty("kotlin.build.proguard")?.toString()?.toBoolean()
|
||||
?: hasProperty("teamcity")
|
||||
|
||||
val jarBaseName = property("archivesBaseName") as String
|
||||
|
||||
val proguardLibraryJars by configurations.creating
|
||||
@@ -58,9 +53,8 @@ val mainKtsRelocatedDepsRootPackage = "$mainKtsRootPackage.relocatedDeps"
|
||||
val packJar by task<ShadowJar> {
|
||||
configurations = emptyList()
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
destinationDir = File(buildDir, "libs")
|
||||
|
||||
setupPublicJar(project.the<BasePluginConvention>().archivesBaseName, "before-proguard")
|
||||
destinationDirectory.set(File(buildDir, "libs"))
|
||||
archiveClassifier.set("before-proguard")
|
||||
|
||||
from(mainSourceSet.output)
|
||||
from(project.configurations.embedded)
|
||||
@@ -68,8 +62,10 @@ val packJar by task<ShadowJar> {
|
||||
// don't add this files to resources classpath to avoid IDE exceptions on kotlin project
|
||||
from("jar-resources")
|
||||
|
||||
packagesToRelocate.forEach {
|
||||
relocate(it, "$mainKtsRelocatedDepsRootPackage.$it")
|
||||
if (kotlinBuildProperties.relocation) {
|
||||
packagesToRelocate.forEach {
|
||||
relocate(it, "$mainKtsRelocatedDepsRootPackage.$it")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +86,7 @@ val proguard by task<ProGuardTask> {
|
||||
}
|
||||
|
||||
val resultJar = tasks.register<Jar>("resultJar") {
|
||||
val pack = if (shrink) proguard else packJar
|
||||
val pack = if (kotlinBuildProperties.proguard) proguard else packJar
|
||||
dependsOn(pack)
|
||||
setupPublicJar(jarBaseName)
|
||||
from {
|
||||
|
||||
Reference in New Issue
Block a user