From 51cf323fbcad28de27350777ec9b079760e0e449 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Fri, 22 Nov 2024 10:38:13 +0100 Subject: [PATCH] Move JSpecify from `provided` to `compile` scope [JSpecify](https://jspecify.dev/) is a nullability annotation library with a [large list of supporters](https://jspecify.dev/about/). It is the recommended library to solve [LOG4J2-1477](https://issues.apache.org/jira/browse/LOG4J2-1477). The usage of JSpecify as `provided` library has however a drawback: if users don't have JSpecify on their stack, they'll get a Javac Linter warning whenever they use a class with nullability annotations (see [#3110](https://github.com/apache/logging-log4j2/issues/3110) for example. Since JSpecify is an annotation with `RUNTIME` retention and is not covered by [JDK-8342833](https://bugs.openjdk.org/browse/JDK-8342833), the easiest solution provided by this PR is: - Move JSpecify from the `provided` to the `compile` scope. This will inflate users dependency stack by a whooping 4000 bytes. - Mark JSpecify as optional for OSGi and JPMS, so users can exclude the dependency if they wish to do it. In practice, this change should be neutral for users and will allow us to add nullability annotations to important class, such as `Logger` without breaking the build of users that use the [`-Werror` compiler flag](https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html#option-Werror). --- log4j-api-test/pom.xml | 22 ++++++++++++++++++++++ log4j-api/pom.xml | 15 +++++++++------ log4j-core-test/pom.xml | 1 + log4j-core/pom.xml | 33 +++++++++++++++++++++++++++------ log4j-fuzz-test/pom.xml | 13 ++++++++++++- log4j-taglib/pom.xml | 19 +++++++++++++++++-- log4j-to-jul/pom.xml | 22 ++++++++++++++++------ log4j-to-slf4j/pom.xml | 28 ++++++++++++++++++++++------ pom.xml | 12 ------------ 9 files changed, 126 insertions(+), 39 deletions(-) diff --git a/log4j-api-test/pom.xml b/log4j-api-test/pom.xml index aef8a1b5d64..a30086d2b5a 100644 --- a/log4j-api-test/pom.xml +++ b/log4j-api-test/pom.xml @@ -69,102 +69,124 @@ ~ It is used in StackLocatorUtilTest through a Class.forName --> + org.apache.logging.log4j log4j-api + org.apache.commons commons-lang3 + org.hamcrest hamcrest + junit junit + org.junit.jupiter junit-jupiter-api + org.junit-pioneer junit-pioneer + org.junit.platform junit-platform-commons + org.apache.maven maven-core + org.apache.maven maven-model + org.codehaus.plexus plexus-utils + org.assertj assertj-core + com.fasterxml.jackson.core jackson-core test + com.fasterxml.jackson.core jackson-databind test + org.junit.jupiter junit-jupiter-engine test + org.junit.jupiter junit-jupiter-params test + org.mockito mockito-core + org.mockito mockito-inline test + org.jspecify jspecify test + org.osgi org.osgi.core test + uk.org.webcompere system-stubs-core test + uk.org.webcompere system-stubs-jupiter test + diff --git a/log4j-api/pom.xml b/log4j-api/pom.xml index 4b0525466df..8f38096247c 100644 --- a/log4j-api/pom.xml +++ b/log4j-api/pom.xml @@ -47,7 +47,7 @@ !sun.reflect, - + org.jspecify.*;resolution:=optional @@ -63,16 +63,19 @@ - org.jspecify - jspecify + org.osgi + org.osgi.core provided + - org.osgi - org.osgi.core - provided + org.jspecify + jspecify + diff --git a/log4j-core-test/pom.xml b/log4j-core-test/pom.xml index 8c8cbc19bbd..7e13dee6640 100644 --- a/log4j-core-test/pom.xml +++ b/log4j-core-test/pom.xml @@ -254,6 +254,7 @@ jspecify test + com.sun.mail javax.mail diff --git a/log4j-core/pom.xml b/log4j-core/pom.xml index f5693dc2e92..6d0565627ad 100644 --- a/log4j-core/pom.xml +++ b/log4j-core/pom.xml @@ -53,7 +53,7 @@ --> true - + org.jspecify.*;resolution:=optional, com.conversantmedia.util.concurrent;resolution:=optional; @@ -108,12 +108,14 @@ + javax.activation javax.activation-api provided true + javax.jms @@ -121,6 +123,7 @@ provided true + javax.mail @@ -128,94 +131,112 @@ provided true - - org.jspecify - jspecify - provided - + org.osgi org.osgi.core provided + org.apache.logging.log4j log4j-api + org.apache.commons commons-compress true + org.apache.commons commons-csv true + com.conversantmedia disruptor true + com.lmax disruptor true + com.fasterxml.jackson.core jackson-core true + com.fasterxml.jackson.core jackson-databind true + com.fasterxml.jackson.dataformat jackson-dataformat-xml true + com.fasterxml.jackson.dataformat jackson-dataformat-yaml true + org.jctools jctools-core true + org.zeromq jeromq true + + + + org.jspecify + jspecify + + org.apache.kafka kafka-clients true + com.sun.mail javax.mail runtime true + diff --git a/log4j-fuzz-test/pom.xml b/log4j-fuzz-test/pom.xml index ba7cca9ce02..752f684c76a 100644 --- a/log4j-fuzz-test/pom.xml +++ b/log4j-fuzz-test/pom.xml @@ -41,6 +41,15 @@ 20240303 + + + org.jspecify.*;resolution:=optional + + + + org.jspecify;transitive=false + + @@ -50,10 +59,12 @@ log4j-core + org.jspecify jspecify - provided diff --git a/log4j-taglib/pom.xml b/log4j-taglib/pom.xml index 3855d8f441f..dc66ff62c61 100644 --- a/log4j-taglib/pom.xml +++ b/log4j-taglib/pom.xml @@ -32,7 +32,7 @@ ~ OSGi and JPMS options --> - + org.jspecify.*;resolution:=optional @@ -44,60 +44,75 @@ org.apache.logging.log4j.core + + javax.servlet.jsp javax.servlet.jsp-api provided + javax.servlet javax.servlet-api provided + org.apache.logging.log4j log4j-api + org.apache.logging.log4j log4j-web true + + org.jspecify jspecify - provided + org.apache.logging.log4j log4j-core test + org.apache.logging.log4j log4j-core-test test + commons-logging commons-logging test + org.junit.jupiter junit-jupiter-engine test + org.junit.vintage junit-vintage-engine test + org.springframework spring-test test + diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 54899fad282..3d683e2319e 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -31,7 +31,7 @@ - + org.jspecify.*;resolution:=optional @@ -41,39 +41,49 @@ - - org.jspecify - jspecify - provided - + org.osgi org.osgi.core provided + org.apache.logging.log4j log4j-api + + + + org.jspecify + jspecify + + org.assertj assertj-core test + com.google.guava guava-testlib test + org.junit.jupiter junit-jupiter-engine test + org.junit.vintage junit-vintage-engine test + diff --git a/log4j-to-slf4j/pom.xml b/log4j-to-slf4j/pom.xml index 68f305133aa..1120f846017 100644 --- a/log4j-to-slf4j/pom.xml +++ b/log4j-to-slf4j/pom.xml @@ -40,7 +40,7 @@ --> [1.7,3) - + org.jspecify.*;resolution:=optional, org.slf4j.*;version="${slf4j.support.range}" @@ -64,70 +64,86 @@ + org.osgi org.osgi.core provided - - org.jspecify - jspecify - provided - + org.apache.logging.log4j log4j-api + + + + org.jspecify + jspecify + + org.slf4j slf4j-api + org.assertj assertj-core test + org.hamcrest hamcrest test + org.junit.jupiter junit-jupiter-engine test + org.junit.jupiter junit-jupiter-params test + ch.qos.logback logback-classic test + ch.qos.logback logback-core test + ch.qos.logback logback-core test-jar test + org.apache.logging.log4j log4j-api-test test + org.mockito mockito-core test + diff --git a/pom.xml b/pom.xml index babb336a735..942280c8ad7 100644 --- a/pom.xml +++ b/pom.xml @@ -977,18 +977,6 @@ - - - - org.jspecify - jspecify - ${jspecify.version} - - -