jsonschema2pojo icon indicating copy to clipboard operation
jsonschema2pojo copied to clipboard

Maven plugin's `includeGeneratedAnnotation` does not support `jakarta.annotation.Generated`

Open anno1985 opened this issue 2 years ago • 16 comments

When using both includeJsr303Annotations and includeGeneratedAnnotation, it seems one still gets javax.annotation.(processing.)Generated instead of jakarta.annotaiton.Generated.

anno1985 avatar Jan 05 '23 14:01 anno1985

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

unkish avatar Jan 05 '23 18:01 unkish

So I guess javax has become jakarta, and now we have another Generated annotation to throw into the mix :)

joelittlejohn avatar Jan 05 '23 18:01 joelittlejohn

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>

unkish avatar Jan 06 '23 06:01 unkish

:weary:

joelittlejohn avatar Jan 12 '23 19:01 joelittlejohn

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!

joelittlejohn avatar Jan 12 '23 19:01 joelittlejohn

I think it's mostly political reasons between Java Core and J2EE.

eirnym avatar Jan 12 '23 20:01 eirnym

Hi any updates on this? @joelittlejohn This is blocking JDK17+ compatibility which is required for CVE fixes.

darkmastermindz avatar Dec 21 '23 18:12 darkmastermindz

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.

GregDThomas avatar Feb 07 '24 09:02 GregDThomas

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')
            }
        }
    }

GregDThomas avatar Feb 07 '24 09:02 GregDThomas

@joelittlejohn after reading #1586 as well, I'm thinking a PR for an useJakartaAnnotation to just cover this scenario would be a cleaner solution - thoughts on this proposal?

darkmastermindz avatar Feb 14 '24 04:02 darkmastermindz

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!

magicDGS avatar May 11 '24 20:05 magicDGS