This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/main by this push:
new e4553762d9 Fail build for `static transitive` modules
e4553762d9 is described below
commit e4553762d97b2d8d31bdb00ae3abf0ef6ecc490a
Author: Piotr P. Karwasz <[email protected]>
AuthorDate: Sun Sep 8 10:58:36 2024 +0200
Fail build for `static transitive` modules
This adds a Groovy script that fails the build
if any optional JPMS module has the `transitive` qualifier.
We remove the `transitive` modifier from all optional dependencies.
Closes #2929.
Co-authored-by: Volkan Yazıcı <[email protected]>
---
log4j-core/pom.xml | 1 +
log4j-jul/pom.xml | 6 +++--
log4j-kit/pom.xml | 5 +++-
log4j-parent/pom.xml | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++
log4j-plugins/pom.xml | 4 ++++
log4j-to-jul/pom.xml | 4 ++++
log4j-to-slf4j/pom.xml | 4 ++++
7 files changed, 84 insertions(+), 3 deletions(-)
diff --git a/log4j-core/pom.xml b/log4j-core/pom.xml
index ecc230b326..b75b0f94f3 100644
--- a/log4j-core/pom.xml
+++ b/log4j-core/pom.xml
@@ -66,6 +66,7 @@
java.xml;transitive=false,
jdk.unsupported;transitive=false,
org.fusesource.jansi;transitive=false,
+ org.jspecify;transitive=false
</bnd-extra-module-options>
<log4j.docgen.pluginDescriptorsDir>${log4j.docgen.pluginDescriptorsDir.phase1}</log4j.docgen.pluginDescriptorsDir>
diff --git a/log4j-jul/pom.xml b/log4j-jul/pom.xml
index 00f55786df..5fdabdc717 100644
--- a/log4j-jul/pom.xml
+++ b/log4j-jul/pom.xml
@@ -29,8 +29,6 @@
<description>The Apache Log4j implementation of
java.util.logging</description>
<properties>
- <log4jParentDir>${basedir}/..</log4jParentDir>
-
<!--
~ OSGi and JPMS options
-->
@@ -38,6 +36,10 @@
<!-- Log4j Core is optional -->
org.apache.logging.log4j.core.*;resolution:=optional
</bnd-extra-package-options>
+ <bnd-extra-module-options>
+ <!-- Optional dependencies can not be transitive -->
+ org.apache.logging.log4j.core;transitive=false
+ </bnd-extra-module-options>
<!-- PTS requires using the JUnit Platform, which interferes with JUL
initialization -->
<predictive.test.selection.enabled>false</predictive.test.selection.enabled>
diff --git a/log4j-kit/pom.xml b/log4j-kit/pom.xml
index 7833f16922..9384222456 100644
--- a/log4j-kit/pom.xml
+++ b/log4j-kit/pom.xml
@@ -35,7 +35,10 @@
<!-- JSpecify is optional at runtime -->
org.jspecify.annotations.*;resolution:=optional
</bnd-extra-package-options>
-
<bnd-extra-module-options>org.jspecify;transitive:=false</bnd-extra-module-options>
+ <bnd-extra-module-options>
+ <!-- Optional dependencies should not be `static` -->
+ org.jspecify;transitive=false
+ </bnd-extra-module-options>
</properties>
<dependencies>
diff --git a/log4j-parent/pom.xml b/log4j-parent/pom.xml
index 9f33bb2420..a899db0c44 100644
--- a/log4j-parent/pom.xml
+++ b/log4j-parent/pom.xml
@@ -87,6 +87,7 @@
<asciidoctor-maven-plugin.version>2.2.4</asciidoctor-maven-plugin.version>
<docker-maven-plugin.version>0.43.4</docker-maven-plugin.version>
<exam-maven-plugin.version>4.13.5</exam-maven-plugin.version>
+ <gmavenplus-plugin.version>3.0.2</gmavenplus-plugin.version>
<!-- `surefire.version` property used in `apache.org:apache`: -->
<surefire.version>3.5.0</surefire.version>
@@ -838,6 +839,68 @@
</executions>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.gmavenplus</groupId>
+ <artifactId>gmavenplus-plugin</artifactId>
+ <version>${gmavenplus-plugin.version}</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.groovy</groupId>
+ <artifactId>groovy-ant</artifactId>
+ <version>${groovy.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.groovy</groupId>
+ <artifactId>groovy</artifactId>
+ <version>${groovy.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <id>ban-static-transitive</id>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ <phase>verify</phase>
+ <configuration>
+ <continueExecuting>false</continueExecuting>
+ <scripts>
+ <script><![CDATA[
+ import java.io.StringWriter
+ import java.util.spi.ToolProvider
+
+ if ("jar" != project.packaging) {
+ log.info("Skipping module descriptor check, since the
project type is not `jar`.")
+ return
+ }
+ String jarFile = project.build.directory + "/" +
project.build.finalName + ".jar";
+ if (!new File(jarFile).exists()) {
+ log.info("Skipping module descriptor check, since `" +
jarFile + "` is missing.")
+ return
+ }
+ StringWriter out = new StringWriter()
+ StringWriter err = new StringWriter()
+ ToolProvider jar =
ToolProvider.findFirst("jar").orElseThrow()
+ int result = jar.run(new PrintWriter(out), new
PrintWriter(err), "-d", "-f", jarFile)
+ if (result != 0) {
+ throw new RuntimeException("Failed to decompile the
module descriptor in `" + jarFile + "`:\n" + err)
+ }
+ log.debug("Module descriptor: " + out)
+ for (String line : out.toString().split("\r?\n", -1)) {
+ if (line.contains("static") &&
line.contains("transitive")) {
+ throw new RuntimeException("The `static` and
`transitive` modifiers should not be use together: " + line)
+ }
+ }
+ log.info("Successfully verified module descriptor in `" +
jarFile + "`.")
+ ]]></script>
+ </scripts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
</plugins>
</build>
diff --git a/log4j-plugins/pom.xml b/log4j-plugins/pom.xml
index 94653a1e4f..ac88ccb680 100644
--- a/log4j-plugins/pom.xml
+++ b/log4j-plugins/pom.xml
@@ -37,6 +37,10 @@
com.google.errorprone.annotations.concurrent;resolution:=optional,
org.jspecify.annotations.*;resolution:=optional
</bnd-extra-package-options>
+ <bnd-extra-module-options>
+ <!-- Optional dependencies should not be `static` -->
+ org.jspecify;transitive=false
+ </bnd-extra-module-options>
</properties>
<dependencies>
diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml
index 477e6cfc84..cf0832e2aa 100644
--- a/log4j-to-jul/pom.xml
+++ b/log4j-to-jul/pom.xml
@@ -34,6 +34,10 @@
<!-- Annotations only -->
org.jspecify.*;resolution:=optional
</bnd-extra-package-options>
+ <bnd-extra-module-options>
+ <!-- Remove `transitive` for optional dependencies -->
+ org.jspecify;transitive=false
+ </bnd-extra-module-options>
</properties>
<dependencies>
diff --git a/log4j-to-slf4j/pom.xml b/log4j-to-slf4j/pom.xml
index 1450ad9aa5..413fde7a59 100644
--- a/log4j-to-slf4j/pom.xml
+++ b/log4j-to-slf4j/pom.xml
@@ -45,6 +45,10 @@
<!-- This bridge also support SLF4J 2.x -->
org.slf4j.*;version="${slf4j.support.range}"
</bnd-extra-package-options>
+ <bnd-extra-module-options>
+ <!-- Remove `transitive` for optional dependencies -->
+ org.jspecify;transitive=false
+ </bnd-extra-module-options>
</properties>
<dependencies>
<dependency>