I go the error message:
module reads package javax.annotation from both jsr305 and java.annotation
In my build.gradle I used these dependencies:`
implementation "javax.annotation:jsr305:1.0" // for @javax.annotation.Nonnull & Nullable
implementation "javax.annotation:javax.annotation-api:1.3.2" // for @javax.annotation.Generated`
In my OpenAPI generated source these annotations are used:
@javax.annotation.Nonnull & Nullable`
@javax.annotation.Generated`
I tried to use an exclude but it didn't work:
implementation ('javax.annotation:jsr305:1.0') {
exclude group:"javax.annotation", module: "javax.annotation-api"
}
Solution
Move from javax.annotation to jakarta.annotation in source code:
and in my build.gradle include this dependency:
And in my module-info.java I included:
n.b. The other dependency I found
jakarta.annotation:jakarta.annotation-api:1.3.5didn't have all the annotations I wanted, only @javax.annotation.Generated and not Nonnull & Nullable, and so I usedone.gfw:jakarta.annotation-api:2.1.1As an aside, my source code was generated by the OpenAPI generator and I included the option
useJakartaEe: 'true'in the generator's config to generate "jakarta.annotation" in place of "javax.annotation". In my OpenAPI generator's project - separate from the above project - here's my config in its build.gradle:Hope this helps.