I use gRPC to generate java code '@javax.annotation.Generated' and it reports 'Error:(20,18) java: cannot find symbol'. How to solve it?
Asked Answered
C

6

12

I use gRPC to generate code '@javax.annotation.Generated' like below picture.

![enter image description here

Then I use maven to build the project, and it reports 'Error:(20,18) java: cannot find symbol' like below picture.

enter image description here

How to solve it?

Complexity answered 1/4, 2020 at 9:58 Comment(0)
D
27

you can add javax.annotation-api dependencies to you maven pom.xml to resolve the annotation.

<dependency>
    <groupId>javax.annotation</groupId>
    <artifactId>javax.annotation-api</artifactId>
    <version>1.2</version>
</dependency>
Dorran answered 1/4, 2020 at 16:31 Comment(0)
N
6

In my case this was caused by building the project on a system with too new version of Java accidentally installed (19 instead of 8). Changing Java version from 19 to 8 in File -> Project Structure fixed the issue for me.

Norbert answered 22/11, 2022 at 10:9 Comment(1)
This exactly fixed my issue.Instantly
M
1

When I use querydsl, I meet the same similar situation in generated source.

I solved this ploblem by uncheck "Use '--release' option for cross-compilation (Java 9 and later ) in Setting "Build, Execution, Deployment > Compiler > Java Compiler" menu.

enter image description here

Malayoindonesian answered 7/2, 2023 at 2:37 Comment(0)
L
1

My problem involved upgrading my Java platform (JDK8 -> JDK17) underneath the codebase (which contained Swagger codegen files).

Solution was to mass-refactor all @javax.annotation.Generated to @javax.annotation.processing.Generated. No dependency changes.

Lacker answered 14/12, 2023 at 19:51 Comment(0)
E
0

I was also facing similar issue for project https://github.com/eugenp/tutorials/tree/master/spring-web-modules/spring-rest-query-language .

Issue - parent and spring-rest-query-language module have source and target as java 8. But I wanted to run this with Intellij having openjdk 21. Few other modules were working correctly with openjdk21 but this module was showing error-

class Generated not found error, javax.annotation.processing Generate not found

Solution -

  1. I have build both parent and spring-rest-query-language with current Intellij setup i.e openjdk 21.

2.I have changed the source and target to 21 as mentioned below snapshot ( in top menu -> Intellij IDEA -> settings -> Build, Execution, Deployment -> java compiler).

enter image description here

Electrophilic answered 26/3 at 12:44 Comment(0)
S
0

For people not wanting to add a dependency on javax.*, it looks like a solution for this was released with the 1.63.0 release of gRPC-java: https://github.com/grpc/grpc-java/pull/10927#issuecomment-2066632469.

Scaphoid answered 3/5 at 16:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.