@@ -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
364364This 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
401406The 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-
0 commit comments