Build: Fix caching of some ShadowJar tasks in the project

To be cacheable relocated shadow jars should not include manifest with
build number. Instead, we repack relocated shadow jar in default jar
task with proper manifest.
This commit is contained in:
Vyacheslav Gerasimov
2022-12-22 22:04:22 +01:00
committed by teamcity
parent a05d49d27e
commit 1fa7c7119b
4 changed files with 65 additions and 77 deletions
+26
View File
@@ -109,6 +109,32 @@ fun Project.runtimeJar(body: Jar.() -> Unit = {}): TaskProvider<out Jar> {
return jarTask
}
fun Project.runtimeJarWithRelocation(body: ShadowJar.() -> Unit = {}): TaskProvider<out Jar> {
noDefaultJar()
val shadowJarTask = tasks.register<ShadowJar>("shadowJar") {
archiveClassifier.set("shadow")
configurations = configurations + listOf(project.configurations["embedded"])
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
body()
}
val runtimeJarTask = tasks.register<Jar>("runtimeJar") {
dependsOn(shadowJarTask)
from {
zipTree(shadowJarTask.get().outputs.files.singleFile)
}
setupPublicJar(project.extensions.getByType<BasePluginExtension>().archivesName.get())
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
project.addArtifact("archives", runtimeJarTask, runtimeJarTask)
project.addArtifact("runtimeElements", runtimeJarTask, runtimeJarTask)
project.addArtifact("apiElements", runtimeJarTask, runtimeJarTask)
return runtimeJarTask
}
fun Project.runtimeJar(task: TaskProvider<ShadowJar>, body: ShadowJar.() -> Unit = {}): TaskProvider<out Jar> {
noDefaultJar()
+17 -32
View File
@@ -32,18 +32,17 @@ sourceSets {
"test" { projectDefault() }
}
val shadows by configurations.creating {
isTransitive = false
}
configurations.getByName("compileOnly").extendsFrom(shadows)
configurations.getByName("testApi").extendsFrom(shadows)
val embedded by configurations
embedded.isTransitive = false
configurations.getByName("compileOnly").extendsFrom(embedded)
configurations.getByName("testApi").extendsFrom(embedded)
dependencies {
api(kotlinStdlib())
shadows(project(":kotlinx-metadata"))
shadows(project(":core:metadata"))
shadows(project(":core:metadata.jvm"))
shadows(protobufLite())
embedded(project(":kotlinx-metadata"))
embedded(project(":core:metadata"))
embedded(project(":core:metadata.jvm"))
embedded(protobufLite())
testImplementation(project(":kotlin-test:kotlin-test-junit"))
testImplementation(commonDependency("junit:junit"))
testImplementation(commonDependency("org.jetbrains.intellij.deps:asm-all"))
@@ -54,40 +53,26 @@ if (deployVersion != null) {
publish()
}
val shadowJarTask = runtimeJar(tasks.register<ShadowJar>("shadowJar")) {
callGroovy("manifestAttributes", manifest, project)
manifest.attributes["Implementation-Version"] = archiveVersion
val runtimeJar = runtimeJarWithRelocation {
from(mainSourceSet.output)
exclude("**/*.proto")
configurations = listOf(shadows)
relocate("org.jetbrains.kotlin", "kotlinx.metadata.internal")
}
val test by tasks
test.dependsOn("shadowJar")
tasks.apiBuild {
inputJar.value(shadowJarTask.flatMap { it.archiveFile })
inputJar.value(runtimeJar.flatMap { it.archiveFile })
}
apiValidation {
ignoredPackages.add("kotlinx.metadata.internal")
nonPublicMarkers.addAll(listOf(
"kotlinx.metadata.internal.IgnoreInApiDump",
"kotlinx.metadata.jvm.internal.IgnoreInApiDump"
))
nonPublicMarkers.addAll(
listOf(
"kotlinx.metadata.internal.IgnoreInApiDump",
"kotlinx.metadata.jvm.internal.IgnoreInApiDump"
)
)
}
sourcesJar {
for (dependency in shadows.dependencies) {
if (dependency is ProjectDependency) {
val javaPlugin = dependency.dependencyProject.convention.findPlugin(JavaPluginConvention::class.java)
if (javaPlugin != null) {
from(javaPlugin.sourceSets["main"].allSource)
}
}
}
}
sourcesJar()
javadocJar()
@@ -16,50 +16,35 @@ sourceSets {
"main" { projectDefault() }
}
val shadows by configurations.creating {
isTransitive = false
}
configurations.getByName("compileOnly").extendsFrom(shadows)
configurations.getByName("testApi").extendsFrom(shadows)
val embedded by configurations
embedded.isTransitive = false
configurations.getByName("compileOnly").extendsFrom(embedded)
configurations.getByName("testApi").extendsFrom(embedded)
dependencies {
api(kotlinStdlib())
shadows(project(":kotlinx-metadata"))
shadows(project(":core:compiler.common"))
shadows(project(":core:metadata"))
shadows(project(":core:deserialization"))
shadows(project(":core:deserialization.common"))
shadows(project(":compiler:serialization"))
shadows(project(":kotlin-util-klib-metadata"))
shadows(project(":kotlin-util-klib"))
shadows(project(":kotlin-util-io"))
shadows(protobufLite())
embedded(project(":kotlinx-metadata"))
embedded(project(":core:compiler.common"))
embedded(project(":core:metadata"))
embedded(project(":core:deserialization"))
embedded(project(":core:deserialization.common"))
embedded(project(":compiler:serialization"))
embedded(project(":kotlin-util-klib-metadata"))
embedded(project(":kotlin-util-klib"))
embedded(project(":kotlin-util-io"))
embedded(protobufLite())
}
if (deployVersion != null) {
publish()
}
runtimeJar(tasks.register<ShadowJar>("shadowJar")) {
callGroovy("manifestAttributes", manifest, project)
manifest.attributes["Implementation-Version"] = archiveVersion
runtimeJarWithRelocation {
from(mainSourceSet.output)
exclude("**/*.proto")
configurations = listOf(shadows)
relocate("org.jetbrains.kotlin", "kotlinx.metadata.internal")
}
sourcesJar {
for (dependency in shadows.dependencies) {
if (dependency is ProjectDependency) {
val javaPlugin = dependency.dependencyProject.convention.findPlugin(JavaPluginConvention::class.java)
if (javaPlugin != null) {
from(javaPlugin.sourceSets["main"].allSource)
}
}
}
}
sourcesJar()
javadocJar()
+6 -14
View File
@@ -12,11 +12,10 @@ sourceSets {
"test" { projectDefault() }
}
val shadows: Configuration by configurations.creating {
isTransitive = false
}
configurations.getByName("compileOnly").extendsFrom(shadows)
configurations.getByName("testApi").extendsFrom(shadows)
val embedded by configurations
embedded.isTransitive = false
configurations.getByName("compileOnly").extendsFrom(embedded)
configurations.getByName("testApi").extendsFrom(embedded)
dependencies {
// Should come before dependency on proguarded compiler because StringUtil methods are deleted from it
@@ -36,7 +35,7 @@ dependencies {
// Note that kotlinx-metadata-jvm already includes kotlinx-metadata, core:metadata, core:metadata.jvm,
// and protobuf-lite, so we only need to include kotlinx-metadata-jvm in the shadow jar.
compileOnly(project(":kotlinx-metadata"))
shadows(commonDependency("org.jetbrains.kotlinx:kotlinx-metadata-jvm"))
embedded(commonDependency("org.jetbrains.kotlinx:kotlinx-metadata-jvm"))
compileOnly(intellijCore())
compileOnly(commonDependency("org.jetbrains.intellij.deps:asm-all"))
@@ -50,14 +49,8 @@ optInToExperimentalCompilerApi()
publish()
noDefaultJar()
val shadowJar = runtimeJar(tasks.register<ShadowJar>("shadowJar")) {
callGroovy("manifestAttributes", manifest, project)
manifest.attributes["Implementation-Version"] = archiveVersion
runtimeJarWithRelocation {
from(mainSourceSet.output)
configurations = listOf(shadows)
relocate("kotlinx.metadata", "org.jetbrains.kotlin.jvm.abi.kotlinx.metadata")
mergeServiceFiles() // This is needed to relocate the services files for kotlinx.metadata
}
@@ -69,7 +62,6 @@ javadocJar()
projectTest(parallel = true) {
workingDir = rootDir
dependsOn(":dist")
dependsOn(shadowJar)
}
testsJar()