Skip to content

Commit c5f2441

Browse files
committed
JAVA-2010: Make dependencies to annotations required again
1 parent 1134c70 commit c5f2441

6 files changed

Lines changed: 32 additions & 47 deletions

File tree

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### 4.0.0-beta3 (in progress)
66

7+
- [improvement] JAVA-2010: Make dependencies to annotations required again
78
- [improvement] JAVA-1978: Add a config option to keep contact points unresolved
89
- [bug] JAVA-2000: Fix ConcurrentModificationException during channel shutdown
910
- [improvement] JAVA-2002: Reimplement TypeCodec.accepts to improve performance

core-shaded/pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,10 @@
8989
<dependency>
9090
<groupId>com.github.stephenc.jcip</groupId>
9191
<artifactId>jcip-annotations</artifactId>
92-
<optional>true</optional>
9392
</dependency>
9493
<dependency>
9594
<groupId>com.github.spotbugs</groupId>
9695
<artifactId>spotbugs-annotations</artifactId>
97-
<optional>true</optional>
9896
</dependency>
9997
</dependencies>
10098

core/pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,10 @@
8686
<dependency>
8787
<groupId>com.github.stephenc.jcip</groupId>
8888
<artifactId>jcip-annotations</artifactId>
89-
<optional>true</optional>
9089
</dependency>
9190
<dependency>
9291
<groupId>com.github.spotbugs</groupId>
9392
<artifactId>spotbugs-annotations</artifactId>
94-
<optional>true</optional>
9593
</dependency>
9694
<dependency>
9795
<groupId>ch.qos.logback</groupId>

distribution/pom.xml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,6 @@
4545
<artifactId>java-driver-query-builder</artifactId>
4646
<version>${project.version}</version>
4747
</dependency>
48-
<!--
49-
The annotations are optional dependencies, but it's nice to show annotations in the javadocs
50-
so redeclare them.
51-
-->
52-
<dependency>
53-
<groupId>com.github.stephenc.jcip</groupId>
54-
<artifactId>jcip-annotations</artifactId>
55-
</dependency>
56-
<dependency>
57-
<groupId>com.github.spotbugs</groupId>
58-
<artifactId>spotbugs-annotations</artifactId>
59-
</dependency>
6048
</dependencies>
6149

6250
<build>
@@ -120,10 +108,6 @@
120108
</goals>
121109
<configuration>
122110
<includeDependencySources>true</includeDependencySources>
123-
<dependencySourceExcludes>
124-
<exclude>com.github.stephenc.jcip:jcip-annotations</exclude>
125-
<exclude>com.github.spotbugs:spotbugs-annotations</exclude>
126-
</dependencySourceExcludes>
127111
<doctitle>DataStax Java driver for Apache Cassandra® ${project.version} API
128112
</doctitle>
129113
<windowtitle>DataStax Java driver for Apache Cassandra(R) ${project.version} API

manual/core/integration/README.md

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -362,40 +362,45 @@ The driver team uses annotations to document certain aspects of the code:
362362
* nullability with [SpotBugs](https://spotbugs.github.io/) annotations `@Nullable` and `@NonNull`.
363363

364364
This is mostly used during development; while these annotations are retained in class files, they
365-
serve no purpose at runtime. Whether to make them optional dependencies is up for debate:
366-
367-
* if they are required, it's two additional JARs that every client has to pull in (admittedly they
368-
are quite small);
369-
* if they are optional, the bytecode will reference missing classes. This is not a blocker, but it
370-
can manifest to the end user in a few ways:
371-
372-
* if you navigate to the driver's sources in your IDE, the missing annotations will be
373-
highlighted as errors (note however that modern IDEs such as IntelliJ IDEA can analyze
374-
nullability annotations even if they are missing from the classpath);
375-
* this produces compiler warnings (see [this discussion][guava] of a similar issue for Google's
376-
Guava library).
377-
378-
The Java driver team has decided to make the dependencies optional. If that creates any problem for
379-
you, the workaround is to redeclare them explicitly in your application:
365+
serve no purpose at runtime. If you want to minimize the number of JARs in your classpath, you can
366+
exclude them:
380367

381368
```xml
382369
<dependency>
383370
<groupId>com.datastax.oss</groupId>
384371
<artifactId>java-driver-core</artifactId>
385372
<version>4.0.0-beta2</version>
373+
<exclusions>
374+
<exclusion>
375+
<groupId>com.github.stephenc.jcip</groupId>
376+
<artifactId>jcip-annotations</artifactId>
377+
</exclusion>
378+
<exclusion>
379+
<groupId>com.github.spotbugs</groupId>
380+
<artifactId>spotbugs-annotations</artifactId>
381+
</exclusion>
382+
</exclusions>
386383
</dependency>
387-
<dependency>
388-
<groupId>com.github.stephenc.jcip</groupId>
389-
<artifactId>jcip-annotations</artifactId>
390-
<version>1.0-1</version>
391-
</dependency>
392-
<dependency>
393-
<groupId>com.github.spotbugs</groupId>
394-
<artifactId>spotbugs-annotations</artifactId>
395-
<version>3.1.3</version>
396-
</dependency>
397384
```
398385

386+
However, there is one case when excluding those dependencies won't work: if you use [annotation
387+
processing] in your build, the Java compiler scans the entire classpath -- including the driver's
388+
classes -- and tries to load all declared annotations. If it can't find the class for an annotation,
389+
you'll get a compiler error:
390+
391+
```
392+
error: cannot access ThreadSafe
393+
class file for net.jcip.annotations.ThreadSafe not found
394+
1 error
395+
```
396+
397+
The workaround is to keep the dependencies.
398+
399+
Sometimes annotation scanning can be triggered involuntarily, if one of your dependencies declares
400+
a processor via the service provider mechanism (check the `META-INF/services` directory in the
401+
JARs). If you are sure that you don't need any annotation processing, you can compile with the
402+
`-proc:none` option and still exclude the dependencies.
403+
399404
#### Mandatory dependencies
400405

401406
The remaining core driver dependencies are the only ones that are truly mandatory:
@@ -412,6 +417,7 @@ The remaining core driver dependencies are the only ones that are truly mandator
412417
[gradle_init]: https://guides.gradle.org/creating-new-gradle-builds/
413418
[downloads]: http://downloads.datastax.com/java-driver/
414419
[guava]: https://github.com/google/guava/issues/2721
420+
[annotation processing]: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html#sthref65
415421

416422
[Session.getMetrics]: https://docs.datastax.com/en/drivers/java/4.0/com/datastax/oss/driver/api/core/session/Session.html#getMetrics--
417423
[SessionBuilder.addContactPoint]: https://docs.datastax.com/en/drivers/java/4.0/com/datastax/oss/driver/api/core/session/SessionBuilder.html#addContactPoint-java.net.InetSocketAddress-

query-builder/pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@
4242
<dependency>
4343
<groupId>com.github.stephenc.jcip</groupId>
4444
<artifactId>jcip-annotations</artifactId>
45-
<optional>true</optional>
4645
</dependency>
4746
<dependency>
4847
<groupId>com.github.spotbugs</groupId>
4948
<artifactId>spotbugs-annotations</artifactId>
50-
<optional>true</optional>
5149
</dependency>
5250
<dependency>
5351
<groupId>junit</groupId>

0 commit comments

Comments
 (0)