Open anno1985 opened 1 year ago
Hi
I'm not sure whether there was intent/consideration to use/offer @Generated
from javax/jakarta annotations package.
Current solution is attempting to add javax.annotation.processing.Generated if it's resolvable (java version used to run plugin is 9+) or fallback to javax.annotation.Generated
See: https://github.com/joelittlejohn/jsonschema2pojo/blob/78ec2954c02ec18cfc886aa97c648153dfdca3be/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/AnnotationHelper.java#L25-L26 https://github.com/joelittlejohn/jsonschema2pojo/blob/78ec2954c02ec18cfc886aa97c648153dfdca3be/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/AnnotationHelper.java#L42-L46
Please also note that both jsr303 and jsr349 are about bean validation, which would be javax.validation
/jakarta.validation
So I guess javax has become jakarta, and now we have another Generated annotation to throw into the mix :)
Current annotations are part of the JRE, thus shouldn't require additional dependencies.
Would throwing in jakarta.annotation
in the mix mean yet another flag? As both:
includeJsr303Annotations
and useJakartaValidation
are about validation api:
https://github.com/joelittlejohn/jsonschema2pojo/blob/8e772064776c51376d63c35674e6dd5a0d5e123c/pom.xml#L373-L382
Whereas jakarta.annotaiton.Generated would be about annotations:
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>2.1.1</version>
</dependency>
:weary:
It's funny how an annotation is such a trivial thing, just a tag with no behaviour at all, but it's bounced around so many different locations over the years. Why can't they just include this trivial annotation in Java's core API!
I think it's mostly political reasons between Java Core and J2EE.
Hi any updates on this? @joelittlejohn This is blocking JDK17+ compatibility which is required for CVE fixes.
FWIW, https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-gradle-plugin/README.adoc has the same problem (i.e. javax vs jakarta) - and overcomes it with a single flag "useJakartaEe= true/false" to determine if it uses javax. or jakarta. style annotations.
In the meantime, I've overcome this issue with the following bit of Gradle;
// Until https://github.com/joelittlejohn/jsonschema2pojo/issues/1461 is fixed, correct the package for the "@Generated" annotation
tasks.named('generateJsonSchema2Pojo') {
finalizedBy('makeJakartaAnnotationsCompatible')
}
tasks.register('makeJakartaAnnotationsCompatible') {
doLast {
ant.replaceregexp(match:'javax.annotation.processing.Generated', replace:'jakarta.annotation.Generated', flags:'g', byline:true) {
fileset(dir: 'build/generated-sources/js2p', includes: '**/*.java')
}
}
}
@joelittlejohn after reading #1586 as well, I'm thinking a PR for an useJakartaAnnotation= true/false
or useJakartaEe= true/false
to just cover this scenario would be a cleaner solution (similar to #1280) - thoughts on this proposal?
Is someboy taking over this issue? It would be great to have a way to fully use jakarta instead of require javax just for the generated annotation. Thanks in advance!
When using both
includeJsr303Annotations
andincludeGeneratedAnnotation
, it seems one still getsjavax.annotation.(processing.)Generated
instead ofjakarta.annotaiton.Generated
.