Build: Introduce flag for disabling jar post processing
proguard, relocation, etc.
This commit is contained in:
@@ -28,7 +28,8 @@ class KotlinBuildProperties(
|
||||
|
||||
private operator fun get(key: String): Any? = localProperties.getProperty(key) ?: propertiesProvider.getProperty(key)
|
||||
|
||||
private fun getBoolean(key: String): Boolean = this[key]?.toString()?.toBoolean() == true
|
||||
private fun getBoolean(key: String, default: Boolean = false): Boolean =
|
||||
(this[key]?.toString()?.toBoolean() ?: default) == true
|
||||
|
||||
val isJpsBuildEnabled: Boolean = getBoolean("jpsBuild")
|
||||
|
||||
@@ -70,9 +71,17 @@ class KotlinBuildProperties(
|
||||
}
|
||||
return kotlinUltimateExists && (explicitlyEnabled || isTeamcityBuild)
|
||||
}
|
||||
|
||||
val postProcessing: Boolean get() = isTeamcityBuild || getBoolean("kotlin.build.postprocessing", true)
|
||||
|
||||
val relocation: Boolean get() = postProcessing
|
||||
|
||||
val proguard: Boolean get() = postProcessing && getBoolean("kotlin.build.proguard")
|
||||
|
||||
val jsIrDist: Boolean get() = getBoolean("kotlin.stdlib.js.ir.dist")
|
||||
}
|
||||
|
||||
private const val extensionName = "kotlinBuildFlags"
|
||||
private const val extensionName = "kotlinBuildProperties"
|
||||
|
||||
class ProjectProperties(val project: Project) : PropertiesProvider {
|
||||
override val rootProjectDir: File
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -12,11 +12,6 @@ plugins {
|
||||
java
|
||||
}
|
||||
|
||||
// You can run Gradle with "-Pkotlin.build.proguard=true" to enable ProGuard run on kotlin-compiler.jar (on TeamCity, ProGuard always runs)
|
||||
val shrink = findProperty("kotlin.build.proguard")?.toString()?.toBoolean() ?: hasProperty("teamcity")
|
||||
|
||||
val jsIrDist = findProperty("kotlin.stdlib.js.ir.dist")?.toString()?.toBoolean() == true
|
||||
|
||||
val fatJarContents by configurations.creating
|
||||
val fatJarContentsStripMetadata by configurations.creating
|
||||
val fatJarContentsStripServices by configurations.creating
|
||||
@@ -85,10 +80,10 @@ val distLibraryProjects = listOfNotNull(
|
||||
":kotlin-scripting-compiler",
|
||||
":kotlin-scripting-compiler-impl",
|
||||
":kotlin-scripting-jvm",
|
||||
":kotlin-stdlib-js-ir".takeIf { jsIrDist },
|
||||
":kotlin-stdlib-js-ir".takeIf { kotlinBuildProperties.jsIrDist },
|
||||
":kotlin-source-sections-compiler-plugin",
|
||||
":kotlin-test:kotlin-test-js",
|
||||
":kotlin-test:kotlin-test-js-ir".takeIf { jsIrDist },
|
||||
":kotlin-test:kotlin-test-js-ir".takeIf { kotlinBuildProperties.jsIrDist },
|
||||
":kotlin-test:kotlin-test-junit",
|
||||
":kotlin-test:kotlin-test-junit5",
|
||||
":kotlin-test:kotlin-test-jvm",
|
||||
@@ -109,9 +104,9 @@ val distCompilerPluginProjects = listOf(
|
||||
val distSourcesProjects = listOfNotNull(
|
||||
":kotlin-annotations-jvm",
|
||||
":kotlin-script-runtime",
|
||||
":kotlin-stdlib-js-ir".takeIf { jsIrDist },
|
||||
":kotlin-stdlib-js-ir".takeIf { kotlinBuildProperties.jsIrDist },
|
||||
":kotlin-test:kotlin-test-js",
|
||||
":kotlin-test:kotlin-test-js-ir".takeIf { jsIrDist },
|
||||
":kotlin-test:kotlin-test-js-ir".takeIf { kotlinBuildProperties.jsIrDist },
|
||||
":kotlin-test:kotlin-test-junit",
|
||||
":kotlin-test:kotlin-test-junit5",
|
||||
":kotlin-test:kotlin-test-jvm",
|
||||
@@ -262,7 +257,7 @@ val proguard by task<ProGuardTask> {
|
||||
}
|
||||
}
|
||||
|
||||
val pack = if (shrink) proguard else packCompiler
|
||||
val pack = if (kotlinBuildProperties.proguard) proguard else packCompiler
|
||||
val distDir: String by rootProject.extra
|
||||
|
||||
val jar = runtimeJar {
|
||||
|
||||
Reference in New Issue
Block a user