This is an automated email from the ASF dual-hosted git repository.
snazy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new 7642d4194 Build: ensure LICENSE/NOTICE is in all jars, always add
pom-files to all jars (#3057)
7642d4194 is described below
commit 7642d419435b136de0bb664c9492c9707367c82d
Author: Robert Stupp <[email protected]>
AuthorDate: Mon Nov 17 09:10:26 2025 +0100
Build: ensure LICENSE/NOTICE is in all jars, always add pom-files to all
jars (#3057)
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.
---
.../src/main/kotlin/publishing/MemoizedJarInfo.kt | 45 ++++++++++++------
.../kotlin/publishing/PublishingHelperPlugin.kt | 16 ++-----
.../src/main/kotlin/publishing/maven-utils.kt | 53 +++++++++-------------
.../apache/polaris/version/TestPolarisVersion.java | 6 +--
4 files changed, 59 insertions(+), 61 deletions(-)
diff --git a/build-logic/src/main/kotlin/publishing/MemoizedJarInfo.kt
b/build-logic/src/main/kotlin/publishing/MemoizedJarInfo.kt
index d77a05e75..f90894efa 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<String, String>
} 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 bafc4cc95..359db21e8 100644
--- a/build-logic/src/main/kotlin/publishing/PublishingHelperPlugin.kt
+++ b/build-logic/src/main/kotlin/publishing/PublishingHelperPlugin.kt
@@ -78,18 +78,8 @@ 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<Jar>().configureEach {
- manifest { MemoizedJarInfo.applyJarManifestAttributes(rootProject,
attributes) }
- }
-
- addAdditionalJarContent(this)
+ tasks.withType<Jar>().configureEach {
+ manifest { MemoizedJarInfo.applyJarManifestAttributes(rootProject,
attributes) }
}
apply(plugin = "maven-publish")
@@ -175,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 4c370f637..4456b9852 100644
--- a/build-logic/src/main/kotlin/publishing/maven-utils.kt
+++ b/build-logic/src/main/kotlin/publishing/maven-utils.kt
@@ -27,10 +27,9 @@ 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.kotlin.dsl.provideDelegate
+import org.gradle.jvm.tasks.Jar
+import org.gradle.kotlin.dsl.withType
@CacheableTask
abstract class GeneratePomProperties : DefaultTask() {
@@ -76,37 +75,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 { 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 { 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 { 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)
}
}
}
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 827d6114d..c23feef28 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();
}
}