OpenAPITools / OpenAPITools/openapi-generator
[BUG] client cannot compile under a java11 JDK: cannot find symbol @javax.annotation.Generated(
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The generated project cannot build under a java 11 JDK. I have other projects that can, not sure what is different with the generated gradle client project.
I have the following declaration in my build.grade file:
task generateSampleClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask/*, dependsOn: "generateOpenApiDocs"*/) {
generatorName = "java"
library = "resttemplate"
inputSpec = "$buildDir/openapi.json"
outputDir = "$rootDir/api-client"
apiPackage = "com.example.client"
invokerPackage = "com.example.invoker"
modelPackage = "com.example.cdm"
configOptions = [
dateLibrary: "java8"
]
groupId = 'com.example'
id = 'client'
skipValidateSpec = true
logToStderr = true
generateAliasAsModel = false
enablePostProcessFile = false
}
openapi-generator version
id 'org.openapi.generator' version '4.3.1'
OpenAPI declaration file content or url
https://petstore.swagger.io/v2/swagger.json
Generation Details
After running the above task from my gradle the client project is generated and I can cd into and build it.
cd api-client
chmod +x gradlew
./gradlew check
Also runtime versions
./gradlew -v
------------------------------------------------------------
Gradle 6.0.1
------------------------------------------------------------
Build time: 2019-11-18 20:25:01 UTC
Revision: fad121066a68c4701acd362daf4287a7c309a0f5
Kotlin: 1.3.50
Groovy: 2.5.8
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 11.0.10 (Eclipse OpenJ9 openj9-0.24.0)
OS: Mac OS X 10.16 x86_64
Once run I get the following errors:
$ ./gradlew check
> Task :compileJava FAILED
.../api-client/src/main/java/com/example/cdm/Order.java:38: error: cannot find symbol
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-08-24T16:18:00.114687-05:00[America/Chicago]")
^
symbol: class Generated
location: package javax.annotation
.../api-client/src/main/java/com/example/cdm/ModelApiResponse.java:34: error: cannot find symbol
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-08-24T16:18:00.114687-05:00[America/Chicago]")
^
symbol: class Generated
location: package javax.annotation
.../api-client/src/main/java/com/example/cdm/Tag.java:33: error: cannot find symbol
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-08-24T16:18:00.114687-05:00[America/Chicago]")
^
symbol: class Generated
location: package javax.annotation
.../api-client/src/main/java/com/example/cdm/Pet.java:41: error: cannot find symbol
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-08-24T16:18:00.114687-05:00[America/Chicago]")
^
symbol: class Generated
location: package javax.annotation
.../api-client/src/main/java/com/example/cdm/Category.java:33: error: cannot find symbol
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-08-24T16:18:00.114687-05:00[America/Chicago]")
^
symbol: class Generated
location: package javax.annotation
.../api-client/src/main/java/com/example/cdm/User.java:39: error: cannot find symbol
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-08-24T16:18:00.114687-05:00[America/Chicago]")
^
symbol: class Generated
location: package javax.annotation
.../api-client/src/main/java/com/example/invoker/ApiClient.java:57: error: cannot find symbol
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-08-24T16:18:00.114687-05:00[America/Chicago]")
^
symbol: class Generated
location: package javax.annotation
.../api-client/src/main/java/com/example/invoker/auth/HttpBasicAuth.java:10: error: cannot find symbol
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-08-24T16:18:00.114687-05:00[America/Chicago]")
^
symbol: class Generated
location: package javax.annotation
.../api-client/src/main/java/com/example/invoker/auth/ApiKeyAuth.java:6: error: cannot find symbol
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-08-24T16:18:00.114687-05:00[America/Chicago]")
^
symbol: class Generated
location: package javax.annotation
.../api-client/src/main/java/com/example/invoker/auth/OAuth.java:6: error: cannot find symbol
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-08-24T16:18:00.114687-05:00[America/Chicago]")
^
symbol: class Generated
location: package javax.annotation
.../api-client/src/main/java/com/example/invoker/auth/HttpBearerAuth.java:10: error: cannot find symbol
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-08-24T16:18:00.114687-05:00[America/Chicago]")
^
symbol: class Generated
location: package javax.annotation
.../api-client/src/main/java/com/example/client/PetApi.java:31: error: cannot find symbol
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-08-24T16:18:00.114687-05:00[America/Chicago]")
^
symbol: class Generated
location: package javax.annotation
.../api-client/src/main/java/com/example/client/UserApi.java:29: error: cannot find symbol
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-08-24T16:18:00.114687-05:00[America/Chicago]")
^
symbol: class Generated
location: package javax.annotation
.../api-client/src/main/java/com/example/client/StoreApi.java:29: error: cannot find symbol
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-08-24T16:18:00.114687-05:00[America/Chicago]")
^
symbol: class Generated
location: package javax.annotation
.../api-client/src/main/java/com/example/invoker/RFC3339DateFormat.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
14 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 1s
1 actionable task: 1 executed
As you can see it is hanging up on @javax.annotation.Generated which is no longer at that location in java11. But it is at that location in java8. I can edit other projects and add @javax.annotation.Generated and they work fine with sourceCompatibility JavaVersion.VERSION_1_8 and targetCompatibility JavaVersion.VERSION_1_8
If I run gradlew with -d I see the following command:
2022-08-24T16:27:21.429-0500 [DEBUG] [org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler] Compiler arguments: -source 1.8 -target 1.8 -d...
So it is passing the 1.8 flag to the compiler. Not sure why this is not working.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated api-client/build.gradle and the generated Java files under api-client/src/main/java, then reproduce the failure with ./gradlew check using the reported Java 11 and Gradle 6.0.1 versions. Trace how the generated client handles javax.annotation.Generated; done means the generated project compiles successfully under Java 11.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100