Skip to content

Commit 51cf323

Browse files
committed
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](#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).
1 parent 9299639 commit 51cf323

File tree

9 files changed

+126
-39
lines changed

9 files changed

+126
-39
lines changed

log4j-api-test/pom.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,102 +69,124 @@
6969
~ It is used in StackLocatorUtilTest through a Class.forName
7070
-->
7171
<dependencies>
72+
7273
<dependency>
7374
<groupId>org.apache.logging.log4j</groupId>
7475
<artifactId>log4j-api</artifactId>
7576
</dependency>
77+
7678
<dependency>
7779
<groupId>org.apache.commons</groupId>
7880
<artifactId>commons-lang3</artifactId>
7981
</dependency>
82+
8083
<dependency>
8184
<groupId>org.hamcrest</groupId>
8285
<artifactId>hamcrest</artifactId>
8386
</dependency>
87+
8488
<dependency>
8589
<groupId>junit</groupId>
8690
<artifactId>junit</artifactId>
8791
</dependency>
92+
8893
<dependency>
8994
<groupId>org.junit.jupiter</groupId>
9095
<artifactId>junit-jupiter-api</artifactId>
9196
</dependency>
97+
9298
<dependency>
9399
<groupId>org.junit-pioneer</groupId>
94100
<artifactId>junit-pioneer</artifactId>
95101
</dependency>
102+
96103
<dependency>
97104
<groupId>org.junit.platform</groupId>
98105
<artifactId>junit-platform-commons</artifactId>
99106
</dependency>
107+
100108
<dependency>
101109
<groupId>org.apache.maven</groupId>
102110
<artifactId>maven-core</artifactId>
103111
</dependency>
112+
104113
<dependency>
105114
<groupId>org.apache.maven</groupId>
106115
<artifactId>maven-model</artifactId>
107116
</dependency>
117+
108118
<dependency>
109119
<groupId>org.codehaus.plexus</groupId>
110120
<artifactId>plexus-utils</artifactId>
111121
</dependency>
122+
112123
<dependency>
113124
<groupId>org.assertj</groupId>
114125
<artifactId>assertj-core</artifactId>
115126
</dependency>
127+
116128
<!-- Required for JSON support -->
117129
<dependency>
118130
<groupId>com.fasterxml.jackson.core</groupId>
119131
<artifactId>jackson-core</artifactId>
120132
<scope>test</scope>
121133
</dependency>
134+
122135
<!-- Required for JSON support -->
123136
<dependency>
124137
<groupId>com.fasterxml.jackson.core</groupId>
125138
<artifactId>jackson-databind</artifactId>
126139
<scope>test</scope>
127140
</dependency>
141+
128142
<dependency>
129143
<groupId>org.junit.jupiter</groupId>
130144
<artifactId>junit-jupiter-engine</artifactId>
131145
<scope>test</scope>
132146
</dependency>
147+
133148
<dependency>
134149
<groupId>org.junit.jupiter</groupId>
135150
<artifactId>junit-jupiter-params</artifactId>
136151
<scope>test</scope>
137152
</dependency>
153+
138154
<dependency>
139155
<groupId>org.mockito</groupId>
140156
<artifactId>mockito-core</artifactId>
141157
</dependency>
158+
142159
<dependency>
143160
<groupId>org.mockito</groupId>
144161
<artifactId>mockito-inline</artifactId>
145162
<scope>test</scope>
146163
</dependency>
164+
147165
<dependency>
148166
<groupId>org.jspecify</groupId>
149167
<artifactId>jspecify</artifactId>
150168
<scope>test</scope>
151169
</dependency>
170+
152171
<!-- Used by ServiceLoaderUtilTest -->
153172
<dependency>
154173
<groupId>org.osgi</groupId>
155174
<artifactId>org.osgi.core</artifactId>
156175
<scope>test</scope>
157176
</dependency>
177+
158178
<dependency>
159179
<groupId>uk.org.webcompere</groupId>
160180
<artifactId>system-stubs-core</artifactId>
161181
<scope>test</scope>
162182
</dependency>
183+
163184
<dependency>
164185
<groupId>uk.org.webcompere</groupId>
165186
<artifactId>system-stubs-jupiter</artifactId>
166187
<scope>test</scope>
167188
</dependency>
189+
168190
</dependencies>
169191
<build>
170192
<plugins>

log4j-api/pom.xml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<bnd-extra-package-options>
4848
<!-- Not exported by most OSGi system bundles, hence we use the system classloader to load `sun.reflect.Reflection` -->
4949
!sun.reflect,
50-
<!-- Annotations only -->
50+
<!-- Annotations only: users are allowed to exclude this dependency -->
5151
org.jspecify.*;resolution:=optional
5252
</bnd-extra-package-options>
5353
<bnd-extra-module-options>
@@ -63,16 +63,19 @@
6363
<dependencies>
6464

6565
<dependency>
66-
<groupId>org.jspecify</groupId>
67-
<artifactId>jspecify</artifactId>
66+
<groupId>org.osgi</groupId>
67+
<artifactId>org.osgi.core</artifactId>
6868
<scope>provided</scope>
6969
</dependency>
7070

71+
<!--
72+
~ Effectively optional, but included due to its size and the compilation warnings its absence causes.
73+
-->
7174
<dependency>
72-
<groupId>org.osgi</groupId>
73-
<artifactId>org.osgi.core</artifactId>
74-
<scope>provided</scope>
75+
<groupId>org.jspecify</groupId>
76+
<artifactId>jspecify</artifactId>
7577
</dependency>
78+
7679
</dependencies>
7780
<build>
7881
<plugins>

log4j-core-test/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@
254254
<artifactId>jspecify</artifactId>
255255
<scope>test</scope>
256256
</dependency>
257+
257258
<dependency>
258259
<groupId>com.sun.mail</groupId>
259260
<artifactId>javax.mail</artifactId>

log4j-core/pom.xml

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
-->
5454
<bnd-multi-release>true</bnd-multi-release>
5555
<bnd-extra-package-options>
56-
<!-- Annotations only -->
56+
<!-- Annotations only: users are allowed to exclude this dependency -->
5757
org.jspecify.*;resolution:=optional,
5858
<!-- External optional dependencies -->
5959
com.conversantmedia.util.concurrent;resolution:=optional;
@@ -108,114 +108,135 @@
108108
</properties>
109109

110110
<dependencies>
111+
111112
<dependency>
112113
<groupId>javax.activation</groupId>
113114
<artifactId>javax.activation-api</artifactId>
114115
<scope>provided</scope>
115116
<optional>true</optional>
116117
</dependency>
118+
117119
<!-- Used for JMS appenders (needs an implementation of course) -->
118120
<dependency>
119121
<groupId>javax.jms</groupId>
120122
<artifactId>javax.jms-api</artifactId>
121123
<scope>provided</scope>
122124
<optional>true</optional>
123125
</dependency>
126+
124127
<!-- Required for SMTPAppender -->
125128
<dependency>
126129
<groupId>javax.mail</groupId>
127130
<artifactId>javax.mail-api</artifactId>
128131
<scope>provided</scope>
129132
<optional>true</optional>
130133
</dependency>
131-
<dependency>
132-
<groupId>org.jspecify</groupId>
133-
<artifactId>jspecify</artifactId>
134-
<scope>provided</scope>
135-
</dependency>
134+
136135
<!-- Used for OSGi bundle support -->
137136
<dependency>
138137
<groupId>org.osgi</groupId>
139138
<artifactId>org.osgi.core</artifactId>
140139
<scope>provided</scope>
141140
</dependency>
141+
142142
<!-- Naturally, all implementations require the log4j-api JAR -->
143143
<dependency>
144144
<groupId>org.apache.logging.log4j</groupId>
145145
<artifactId>log4j-api</artifactId>
146146
</dependency>
147+
147148
<!-- Used for compressing to formats other than zip and gz -->
148149
<dependency>
149150
<groupId>org.apache.commons</groupId>
150151
<artifactId>commons-compress</artifactId>
151152
<optional>true</optional>
152153
</dependency>
154+
153155
<!-- Used for the CSV layout -->
154156
<dependency>
155157
<groupId>org.apache.commons</groupId>
156158
<artifactId>commons-csv</artifactId>
157159
<optional>true</optional>
158160
</dependency>
161+
159162
<!-- Alternative implementation of BlockingQueue using Conversant Disruptor for AsyncAppender -->
160163
<dependency>
161164
<groupId>com.conversantmedia</groupId>
162165
<artifactId>disruptor</artifactId>
163166
<optional>true</optional>
164167
</dependency>
168+
165169
<!-- Required for AsyncLoggers -->
166170
<dependency>
167171
<groupId>com.lmax</groupId>
168172
<artifactId>disruptor</artifactId>
169173
<optional>true</optional>
170174
</dependency>
175+
171176
<!-- Required for JSON support -->
172177
<dependency>
173178
<groupId>com.fasterxml.jackson.core</groupId>
174179
<artifactId>jackson-core</artifactId>
175180
<optional>true</optional>
176181
</dependency>
182+
177183
<!-- Required for JSON support -->
178184
<dependency>
179185
<groupId>com.fasterxml.jackson.core</groupId>
180186
<artifactId>jackson-databind</artifactId>
181187
<optional>true</optional>
182188
</dependency>
189+
183190
<!-- Required for XML layout and receiver support -->
184191
<dependency>
185192
<groupId>com.fasterxml.jackson.dataformat</groupId>
186193
<artifactId>jackson-dataformat-xml</artifactId>
187194
<optional>true</optional>
188195
</dependency>
196+
189197
<!-- Required for YAML support (including JSON requirements) -->
190198
<dependency>
191199
<groupId>com.fasterxml.jackson.dataformat</groupId>
192200
<artifactId>jackson-dataformat-yaml</artifactId>
193201
<optional>true</optional>
194202
</dependency>
203+
195204
<!-- Alternative implementation of BlockingQueue using JCTools for AsyncAppender -->
196205
<dependency>
197206
<groupId>org.jctools</groupId>
198207
<artifactId>jctools-core</artifactId>
199208
<optional>true</optional>
200209
</dependency>
210+
201211
<!-- Used for ZeroMQ JeroMQ appender -->
202212
<dependency>
203213
<groupId>org.zeromq</groupId>
204214
<artifactId>jeromq</artifactId>
205215
<optional>true</optional>
206216
</dependency>
217+
218+
<!--
219+
~ Effectively optional, but included due to its size and the compilation warnings its absence causes.
220+
-->
221+
<dependency>
222+
<groupId>org.jspecify</groupId>
223+
<artifactId>jspecify</artifactId>
224+
</dependency>
225+
207226
<!-- Used for Kafka appender -->
208227
<dependency>
209228
<groupId>org.apache.kafka</groupId>
210229
<artifactId>kafka-clients</artifactId>
211230
<optional>true</optional>
212231
</dependency>
232+
213233
<dependency>
214234
<groupId>com.sun.mail</groupId>
215235
<artifactId>javax.mail</artifactId>
216236
<scope>runtime</scope>
217237
<optional>true</optional>
218238
</dependency>
239+
219240
</dependencies>
220241

221242
<build>

log4j-fuzz-test/pom.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@
4141
<!-- dependency versions -->
4242
<json.version>20240303</json.version>
4343

44+
<bnd-extra-package-options>
45+
<!-- Annotations only: users are allowed to exclude this dependency -->
46+
org.jspecify.*;resolution:=optional
47+
</bnd-extra-package-options>
48+
<bnd-extra-module-options>
49+
<!-- Remove `transitive` for optional dependencies -->
50+
org.jspecify;transitive=false
51+
</bnd-extra-module-options>
52+
4453
</properties>
4554

4655
<dependencies>
@@ -50,10 +59,12 @@
5059
<artifactId>log4j-core</artifactId>
5160
</dependency>
5261

62+
<!--
63+
~ Effectively optional, but included due to its size and the compilation warnings its absence causes.
64+
-->
5365
<dependency>
5466
<groupId>org.jspecify</groupId>
5567
<artifactId>jspecify</artifactId>
56-
<scope>provided</scope>
5768
</dependency>
5869

5970
<dependency>

0 commit comments

Comments
 (0)