How to resolve java error: package javax.annotation is not visible, Java version 9
Asked Answered
E

2

6

When building below Spring session sample using gradle: https://docs.spring.io/spring-session/docs/current/reference/html5/guides/boot-findbyusername.html

I encountered an error regarding to java.annotation module, anybody have idea how to resolve that?

/spring-session/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java:22: error: package javax.annotation is not visible
import javax.annotation.PostConstruct;
            ^
  (package javax.annotation is declared in module java.xml.ws.annotation, which is not in the module graph)
warning: unknown enum constant When.MAYBE
  reason: class file for javax.annotation.meta.When not found
1 error
1 warning

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':spring-session-core:compileJava'.
> Compilation failed; see the compiler error output for details.

I tried to add below config in build.gradle however the problem remain.

tasks.withType(AbstractCompile) {
  options.compilerArgs += ["--add-modules", "java.xml.bind"]
}

tasks.withType(Test) {
  jvmArgs += ["--add-modules", "java.xml.bind"]
}
Ellery answered 28/7, 2018 at 3:19 Comment(1)
also add java.xml.ws.annotation with -add-moduleBombazine
T
5

I was getting the same error:

warning: unknown enum constant When.MAYBE
reason: class file for javax.annotation.meta.When not found

For me it was becuase I had annotation processing with lombok which wasn't picked-up with the project dependencies.

In the end I added annotationProcessor as part of the dependencies as follows:

dependencies {
  // ...
  compile('org.springframework.boot:spring-boot-starter-web')
  compileOnly('org.projectlombok:lombok')
  testCompile('org.springframework.boot:spring-boot-starter-test')
  // ...
  annotationProcessor('org.projectlombok:lombok')
}
Tooley answered 9/9, 2019 at 16:2 Comment(0)
E
-5

Seem the sample is not yet upgraded to support java9, downgrade to java8 it runs well.

Ellery answered 28/7, 2018 at 3:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.