Skip to content

Remove transitive modifier from optional dependencies #2930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion log4j-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
<!-- Used in StringBuilders through reflection -->
java.sql;static=true,
<!-- Used in ProcessIdUtil through reflection -->
java.management;static=true
java.management;static=true,
<!-- Remove `transitive` for optional dependencies -->
org.jspecify;transitive=false
</bnd-extra-module-options>

</properties>
Expand Down
1 change: 1 addition & 0 deletions log4j-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
java.naming;transitive=false,
org.apache.commons.csv;transitive=false,
org.fusesource.jansi;transitive=false,
org.jspecify;transitive=false,
org.zeromq.jeromq;transitive=false,
<!-- A module descriptor is only available in version 1.2.16+, hence it is not detected -->
com.conversantmedia.disruptor;substitute="disruptor";transitive=false;static=true,
Expand Down
63 changes: 63 additions & 0 deletions log4j-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<asciidoctor-maven-plugin.version>2.2.4</asciidoctor-maven-plugin.version>
<docker-maven-plugin.version>0.45.0</docker-maven-plugin.version>
<exam-maven-plugin.version>4.13.5</exam-maven-plugin.version>
<gmavenplus-plugin.version>3.0.2</gmavenplus-plugin.version>
<maven-taglib-plugin.version>2.4</maven-taglib-plugin.version>
<!-- `surefire.version` property used in `apache.org:apache`: -->
<surefire.version>3.5.0</surefire.version>
Expand Down Expand Up @@ -995,6 +996,68 @@
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>${gmavenplus-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-ant</artifactId>
<version>${groovy.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.codehaus.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>

Expand Down
4 changes: 4 additions & 0 deletions log4j-to-jul/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 4 additions & 0 deletions log4j-to-slf4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

<slf4j2.version>2.0.16</slf4j2.version>
</properties>
Expand Down
Loading