From 10dd73074eaa28be0b79677ab15921c8b7a4274e Mon Sep 17 00:00:00 2001 From: Robert Stupp Date: Fri, 14 Nov 2025 10:47:55 +0100 Subject: [PATCH 1/4] Build: ensure LICENSE/NOTICE is in all jars, always add pom-files to all jars There are a some inconsistencies between the different kinds of jars and the included information: * LICENSE/NOTICE files are present in the "main" jar and in the sources jar, but not in the javadoc jar. * The Maven pom.xml and pom.properties files are only present for release builds or when explicitly requested. * "Additional" jar-manifest attributes that are only present in release builds. This change fixes the three mentioned issues: * Always include pom.xml and pom.properties in the built jar files. * Always include the additional jar-manifest attributes, except the Git information, which would otherwise render the Gradle build cache ineffective. * Include pom.xml + pom.properties + license/notice in literally all jar files. The Gradle logic to include the license+notice+pom files has been simplified as well. --- .../main/kotlin/publishing/MemoizedJarInfo.kt | 45 +++++++++++----- .../publishing/PublishingHelperPlugin.kt | 17 ++---- .../src/main/kotlin/publishing/maven-utils.kt | 52 ++++++++----------- 3 files changed, 58 insertions(+), 56 deletions(-) diff --git a/build-logic/src/main/kotlin/publishing/MemoizedJarInfo.kt b/build-logic/src/main/kotlin/publishing/MemoizedJarInfo.kt index d77a05e75f..f90894efad 100644 --- a/build-logic/src/main/kotlin/publishing/MemoizedJarInfo.kt +++ b/build-logic/src/main/kotlin/publishing/MemoizedJarInfo.kt @@ -24,8 +24,9 @@ import org.gradle.api.java.archives.Attributes import org.gradle.kotlin.dsl.extra /** - * Helper class to generate Jar manifest attributes including Git commit SHA, Git describe, project - * version and Java specification version. + * Helper class to generate Jar manifest attributes including project version and Java specification + * version. Git information like the commit SHA and Git describe output are only included for + * release builds, or if explicitly requested. */ internal class MemoizedJarInfo { companion object { @@ -39,21 +40,37 @@ internal class MemoizedJarInfo { @Suppress("UNCHECKED_CAST") rootProject.extra["gitReleaseInfo"] as Map } else { - val isRelease = - rootProject.hasProperty("release") || rootProject.hasProperty("jarWithGitInfo") - val gi = GitInfo.memoized(rootProject) + val version = rootProject.version.toString() val javaSpecificationVersion = System.getProperty("java.specification.version") + val includeGitInformation = + rootProject.hasProperty("release") || rootProject.hasProperty("jarWithGitInfo") - val version = rootProject.version.toString() val info = - mapOf( - "Implementation-Version" to version, - "Apache-Polaris-Version" to version, - "Apache-Polaris-Is-Release" to isRelease.toString(), - "Apache-Polaris-Build-Git-Head" to gi.gitHead, - "Apache-Polaris-Build-Git-Describe" to gi.gitDescribe, - "Apache-Polaris-Build-Java-Specification-Version" to javaSpecificationVersion, - ) + if (includeGitInformation) { + val gi = GitInfo.memoized(rootProject) + mapOf( + "Implementation-Version" to version, + "Apache-Polaris-Version" to version, + "Apache-Polaris-Is-Release" to "true", + "Apache-Polaris-Build-Git-Head" to gi.gitHead, + "Apache-Polaris-Build-Git-Describe" to gi.gitDescribe, + "Apache-Polaris-Build-Java-Specification-Version" to javaSpecificationVersion, + ) + } else { + // Not adding Git information here to keep Gradle's up-to-date functionality intact. + // Varying information in the manifest would change the MANIFEST.MF file and the jar. + // If the output changes, the input of dependent tasks is no longer up-to-date and would + // need to be rebuilt. + // This would render the Gradle build-cache ineffective for every Git commit, + // especially in CI, leading to unnecessary long builds. + mapOf( + "Implementation-Version" to version, + "Apache-Polaris-Version" to version, + "Apache-Polaris-Is-Release" to "false", + "Apache-Polaris-Build-Java-Specification-Version" to javaSpecificationVersion, + ) + } + rootProject.extra["gitReleaseInfo"] = info return info } diff --git a/build-logic/src/main/kotlin/publishing/PublishingHelperPlugin.kt b/build-logic/src/main/kotlin/publishing/PublishingHelperPlugin.kt index bafc4cc959..7c0708f495 100644 --- a/build-logic/src/main/kotlin/publishing/PublishingHelperPlugin.kt +++ b/build-logic/src/main/kotlin/publishing/PublishingHelperPlugin.kt @@ -78,20 +78,13 @@ constructor(private val softwareComponentFactory: SoftwareComponentFactory) : Pl project.run { extensions.create("publishingHelper", PublishingHelperExtension::class.java) - val isRelease = project.hasProperty("release") - - // Adds Git/Build/System related information to the generated jars, if the `release` project - // property is present. Do not add that information in development builds, so that the - // generated jars are still cacheable for Gradle. - if (isRelease || project.hasProperty("jarWithGitInfo")) { - // Runs `git`, considered expensive, so guarded behind project properties. - tasks.withType().configureEach { - manifest { MemoizedJarInfo.applyJarManifestAttributes(rootProject, attributes) } - } - - addAdditionalJarContent(this) + tasks.withType().configureEach { + System.err.println("CONFIGURE on $path") + manifest { MemoizedJarInfo.applyJarManifestAttributes(rootProject, attributes) } } + addAdditionalJarContent(this) + apply(plugin = "maven-publish") apply(plugin = "signing") diff --git a/build-logic/src/main/kotlin/publishing/maven-utils.kt b/build-logic/src/main/kotlin/publishing/maven-utils.kt index 4c370f6376..c2d64fb7a0 100644 --- a/build-logic/src/main/kotlin/publishing/maven-utils.kt +++ b/build-logic/src/main/kotlin/publishing/maven-utils.kt @@ -27,10 +27,10 @@ import org.gradle.api.provider.ListProperty import org.gradle.api.tasks.CacheableTask import org.gradle.api.tasks.Input import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.SourceSetContainer -import org.gradle.api.tasks.Sync import org.gradle.api.tasks.TaskAction +import org.gradle.jvm.tasks.Jar import org.gradle.kotlin.dsl.provideDelegate +import org.gradle.kotlin.dsl.withType @CacheableTask abstract class GeneratePomProperties : DefaultTask() { @@ -76,37 +76,29 @@ fun addAdditionalJarContent(project: Project): Unit = val generatePomProperties = tasks.register("generatePomProperties", GeneratePomProperties::class.java) {} - val additionalJarContent = - tasks.register("additionalJarContent", Sync::class.java) { - // Have to manually declare the inputs of this task here on top of the from/include below - inputs.files( - rootProject.layout.files("gradle/jar-licenses/LICENSE", "gradle/jar-licenses/NOTICE") - ) - inputs.property("GAV", "${project.group}:${project.name}:${project.version}") - dependsOn("generatePomFileForMavenPublication") - if (!project.file("src/main/resources/META-INF/LICENSE").exists()) { - from(rootProject.rootDir).include("gradle/jar-licenses/LICENSE").eachFile { - this.path = "META-INF/$sourceName" - } + tasks.withType(Jar::class).configureEach { + if (!project.file("src/main/resources/META-INF/LICENSE").exists()) { + from(rootProject.rootDir).include("gradle/jar-licenses/LICENSE").eachFile { + this.path = "META-INF/$sourceName" } - if (!project.file("src/main/resources/META-INF/NOTICE").exists()) { - from(rootProject.rootDir).include("gradle/jar-licenses/NOTICE").eachFile { - this.path = "META-INF/$sourceName" - } - } - from(tasks.named("generatePomFileForMavenPublication")) { - include("pom-default.xml") - eachFile { this.path = "META-INF/maven/${project.group}/${project.name}/pom.xml" } + } else if (name == "javadocJar") { + from("src/main/resources").include("META-INF/LICENSE") + } + if (!project.file("src/main/resources/META-INF/NOTICE").exists()) { + from(rootProject.rootDir).include("gradle/jar-licenses/NOTICE").eachFile { + this.path = "META-INF/$sourceName" } - into(layout.buildDirectory.dir("license-for-jar")) + } else if (name == "javadocJar") { + from("src/main/resources").include("META-INF/NOTICE") + } + from(tasks.named("generatePomFileForMavenPublication")) { + include("pom-default.xml") + eachFile { this.path = "META-INF/maven/${project.group}/${project.name}/pom.xml" } + } + from(generatePomProperties) { + include("**") + eachFile { path = sourcePath } } - - tasks.named("processResources") { dependsOn("additionalJarContent") } - - val sourceSets: SourceSetContainer by project - sourceSets.named("main") { - resources.srcDir(additionalJarContent) - resources.srcDir(generatePomProperties) } } } From 11aa82a63830d6a27c4a2d89dfc05beff84d124c Mon Sep 17 00:00:00 2001 From: Robert Stupp Date: Fri, 14 Nov 2025 11:34:19 +0100 Subject: [PATCH 2/4] fix --- .../kotlin/publishing/PublishingHelperPlugin.kt | 5 ++--- .../src/main/kotlin/publishing/maven-utils.kt | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/build-logic/src/main/kotlin/publishing/PublishingHelperPlugin.kt b/build-logic/src/main/kotlin/publishing/PublishingHelperPlugin.kt index 7c0708f495..359db21e8a 100644 --- a/build-logic/src/main/kotlin/publishing/PublishingHelperPlugin.kt +++ b/build-logic/src/main/kotlin/publishing/PublishingHelperPlugin.kt @@ -79,12 +79,9 @@ constructor(private val softwareComponentFactory: SoftwareComponentFactory) : Pl extensions.create("publishingHelper", PublishingHelperExtension::class.java) tasks.withType().configureEach { - System.err.println("CONFIGURE on $path") manifest { MemoizedJarInfo.applyJarManifestAttributes(rootProject, attributes) } } - addAdditionalJarContent(this) - apply(plugin = "maven-publish") apply(plugin = "signing") @@ -168,5 +165,7 @@ constructor(private val softwareComponentFactory: SoftwareComponentFactory) : Pl } } } + + addAdditionalJarContent(this) } } diff --git a/build-logic/src/main/kotlin/publishing/maven-utils.kt b/build-logic/src/main/kotlin/publishing/maven-utils.kt index c2d64fb7a0..f9583250cb 100644 --- a/build-logic/src/main/kotlin/publishing/maven-utils.kt +++ b/build-logic/src/main/kotlin/publishing/maven-utils.kt @@ -78,22 +78,22 @@ fun addAdditionalJarContent(project: Project): Unit = tasks.withType(Jar::class).configureEach { if (!project.file("src/main/resources/META-INF/LICENSE").exists()) { - from(rootProject.rootDir).include("gradle/jar-licenses/LICENSE").eachFile { - this.path = "META-INF/$sourceName" + from(rootProject.rootDir) { + include("gradle/jar-licenses/LICENSE").eachFile { path = "META-INF/$sourceName" } } } else if (name == "javadocJar") { - from("src/main/resources").include("META-INF/LICENSE") + from("src/main/resources") { include("META-INF/LICENSE") } } if (!project.file("src/main/resources/META-INF/NOTICE").exists()) { - from(rootProject.rootDir).include("gradle/jar-licenses/NOTICE").eachFile { - this.path = "META-INF/$sourceName" + from(rootProject.rootDir) { + include("gradle/jar-licenses/NOTICE").eachFile { path = "META-INF/$sourceName" } } } else if (name == "javadocJar") { - from("src/main/resources").include("META-INF/NOTICE") + from("src/main/resources") { include("META-INF/NOTICE") } } from(tasks.named("generatePomFileForMavenPublication")) { include("pom-default.xml") - eachFile { this.path = "META-INF/maven/${project.group}/${project.name}/pom.xml" } + eachFile { path = "META-INF/maven/${project.group}/${project.name}/pom.xml" } } from(generatePomProperties) { include("**") From a06e552d89801810e445bf0c29d7f5809071f573 Mon Sep 17 00:00:00 2001 From: Robert Stupp Date: Fri, 14 Nov 2025 12:01:13 +0100 Subject: [PATCH 3/4] rm import --- build-logic/src/main/kotlin/publishing/maven-utils.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/build-logic/src/main/kotlin/publishing/maven-utils.kt b/build-logic/src/main/kotlin/publishing/maven-utils.kt index f9583250cb..4456b9852f 100644 --- a/build-logic/src/main/kotlin/publishing/maven-utils.kt +++ b/build-logic/src/main/kotlin/publishing/maven-utils.kt @@ -29,7 +29,6 @@ import org.gradle.api.tasks.Input import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction import org.gradle.jvm.tasks.Jar -import org.gradle.kotlin.dsl.provideDelegate import org.gradle.kotlin.dsl.withType @CacheableTask From f0fc3eb08165e5117f66584c1decac629b29487b Mon Sep 17 00:00:00 2001 From: Robert Stupp Date: Fri, 14 Nov 2025 12:24:13 +0100 Subject: [PATCH 4/4] adapt test --- .../java/org/apache/polaris/version/TestPolarisVersion.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/version/src/jarTest/java/org/apache/polaris/version/TestPolarisVersion.java b/tools/version/src/jarTest/java/org/apache/polaris/version/TestPolarisVersion.java index 827d6114dd..c23feef280 100644 --- a/tools/version/src/jarTest/java/org/apache/polaris/version/TestPolarisVersion.java +++ b/tools/version/src/jarTest/java/org/apache/polaris/version/TestPolarisVersion.java @@ -55,16 +55,14 @@ public class TestPolarisVersion { @Order(1) public void versionAvailable() { soft.assertThat(polarisVersionString()).isEqualTo(System.getProperty("polarisVersion")); + soft.assertThat(getBuildReleasedVersion()).isNotEmpty(); + soft.assertThat(getBuildJavaSpecificationVersion()).isNotEmpty(); if (isReleaseBuild()) { - soft.assertThat(getBuildReleasedVersion()).isNotEmpty(); soft.assertThat(getBuildGitHead()).isNotEmpty(); soft.assertThat(getBuildGitTag()).isNotEmpty(); - soft.assertThat(getBuildJavaSpecificationVersion()).isNotEmpty(); } else { - soft.assertThat(getBuildReleasedVersion()).isEmpty(); soft.assertThat(getBuildGitHead()).isEmpty(); soft.assertThat(getBuildGitTag()).isEmpty(); - soft.assertThat(getBuildJavaSpecificationVersion()).isEmpty(); } }