Packages com.google.errorprone.annotations and javax.annotation are not visible when built with Guava as dependency with jigsaw
See original GitHub issueI can’t build my project that uses Guava without getting these errors:
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/Development/tmp/target/generated-sources/annotations/com/example/ImmutableExample.java:[5,29] package com.google.errorprone.annotations is not visible
(package com.google.errorprone.annotations is declared in the unnamed module, but module tmp does not read it)
[ERROR] /D:/Development/tmp/target/generated-sources/annotations/com/example/ImmutableExample.java:[6,29] package com.google.errorprone.annotations is not visible
(package com.google.errorprone.annotations is declared in the unnamed module, but module tmp does not read it)
[ERROR] /D:/Development/tmp/target/generated-sources/annotations/com/example/ImmutableExample.java:[10,13] package javax.annotation is not visible
(package javax.annotation is declared in the unnamed module, but module tmp does not read it)
[ERROR] /D:/Development/tmp/target/generated-sources/annotations/com/example/ImmutableExample.java:[11,13] package javax.annotation is not visible
(package javax.annotation is declared in the unnamed module, but module tmp does not read it)
[ERROR] /D:/Development/tmp/target/generated-sources/annotations/com/example/ImmutableExample.java:[12,13] package javax.annotation is not visible
(package javax.annotation is declared in the unnamed module, but module tmp does not read it)
[ERROR] /D:/Development/tmp/target/generated-sources/annotations/com/example/ImmutableExample.java:[13,24] package javax.annotation.concurrent is not visible
(package javax.annotation.concurrent is declared in the unnamed module, but module tmp does not read it)
[ERROR] /D:/Development/tmp/target/generated-sources/annotations/com/example/ImmutableExample.java:[14,24] package javax.annotation.concurrent is not visible
(package javax.annotation.concurrent is declared in the unnamed module, but module tmp does not read it)
[INFO] 7 errors
[INFO] -------------------------------------------------------------
Here’s my MCVE project crafted specially to show the issue at hand:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>tmp</artifactId>
<groupId>com.example</groupId>
<version>1.0.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>org.immutables</groupId>
<artifactId>value</artifactId>
<version>2.8.8</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
<dependency>
<groupId>org.immutables</groupId>
<artifactId>value</artifactId>
<version>2.8.8</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
src/main/java/module-info.java
module tmp {
requires org.immutables.value;
}
src/main/java/com/example/Example.java
package com.example;
import org.immutables.value.Value;
import org.immutables.value.Value.Style.ImplementationVisibility;
@Value.Immutable
@Value.Style(visibility = ImplementationVisibility.PACKAGE)
public abstract class Example {
}
The obvious workaround is to change the module-info.java
to add the following:
requires com.google.errorprone.annotations;
requires jsr305;
But that’s absolutely not a fix.
Simply having guava as a dependency makes this issue happen if I use modules. Removing the Guava dependency makes the issue disappear.
Please fix this by checking whether those modules are already required (in the module-info.java
) at compile time. If they are not: don’t write those annotations so they are not compiled.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top Results From Across the Web
import javax.annotation.* cannot be resolved in Eclipse's Java ...
After importing these two libraries in eclipse if eclipse can not recognize them then you have to add a jar. javax.annotation-api.
Read more >Lombok Changelog
FEATURE: Lombok's @NonNull annotation can now be used on type usages (annotation on type usages has been introduced in JDK 8). @Builder 's...
Read more >Building Modular Java Applications with Gradle - Alex Kudlick
A primer on building a non-trivial modular Java application with ... error: module error.prone.annotations reads package javax.annotation ...
Read more >Diff - platform/prebuilts/tools - Google Git
The JDK doc must be listed after JSR305 (and as an <offlineLink>, not a <link>) so that JSR305 "claims" javax.annotation.
Read more >Guava 23.5 released - Google Groups
Error Prone annotations are only useful is the downstream project uses Error Prone; but Error Prone will actually fail if the dependency is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
BTW when using separate annotation processing path, why not use only annotations module on the regular compilation path?
definitely,
requires static
is even better