Javadoc error on @RequiredArgsConstructor(onConstructor=@__(@Inject))
Asked Answered
N

7

14

I am trying to generate the javadoc using JDK 8 for a bunch of codes using lombok.

I am getting the error below:

error: cannot find symbol
[ERROR] @RequiredArgsConstructor(onConstructor=@__(@Inject))
[ERROR] ^
[ERROR] symbol: class __

Any advice will be much appreciated on how to resolve the error above.

Update: the error is happening using the maven javadoc plugin configured as below:

        <plugin>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.10.3</version>
            <!--
            <configuration>
                <doclet>ch.raffael.doclets.pegdown.PegdownDoclet</doclet>
                <docletArtifact>
                    <groupId>ch.raffael.pegdown-doclet</groupId>
                    <artifactId>pegdown-doclet</artifactId>
                    <version>1.1.1</version>
                </docletArtifact>
                <useStandardDocletOptions>true</useStandardDocletOptions>
            </configuration>
            -->
        </plugin>
Nordgren answered 19/2, 2016 at 2:11 Comment(3)
This isn't a duplicate, as it happens under Maven. The original ticket is for IntelliJCento
For somebody who is looking for a solution like me: I found a solution at #11330465Nordgren
This Q is totally unrelated to the "duplicate" Q and was incorrectly flagged.Galatea
P
8

I had the same issue, resolved by:

  1. Configuring lombok-maven-plugin to

    1. Delombok the classes into target/delombok directory
    2. Don't addOutputDirectory to the compiler source paths
  2. Configure maven-javadoc-plugin to look into the target/delombok directory

A good explanation is also at this similar question

Also, bare in mind that onConstructor is an experimental feature and that with jdk8, you should use (onConstructor_ = @Autowired) instead of jdk7-style onConstructor = @__(@Autowired)

Here is my full config:

<plugin>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok-maven-plugin</artifactId>
    <version>${lombok-maven-plugin-version}</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                 <goal>delombok</goal>
            </goals>
            <configuration>
                <addOutputDirectory>false</addOutputDirectory>
                <sourceDirectory>src/main/java</sourceDirectory>
                <outputDirectory>
                     ${project.build.directory}/delombok
                </outputDirectory>
            </configuration>
       </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>${maven-javadoc-plugin-version}</version>
    <executions>
        <execution>
            <id>attach-javadocs</id>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <sourcepath>target/generated-sources/delombok</sourcepath>
    </configuration>
</plugin>
Placable answered 4/11, 2019 at 17:16 Comment(1)
where did you find that config file ?Camembert
T
4

Adding here just for future reference as on my case I was trying to build on Intelij and the error was due to compiler annotation processors being disabled.

To enable it, go to Intelij preferences, open "Build, Execution, Deployment" -> "Compiler" -> "Annotation Processors" and make sure "Enable annotation processing" is enabled

Enable annotation processing Intelij preference

Tiloine answered 19/2, 2020 at 13:16 Comment(0)
D
0

If you use intellij Idea go to setting and add Lombok plugin to your intellij idea

enter image description here

Dashiell answered 21/7, 2022 at 17:8 Comment(1)
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From ReviewNightshade
B
0

For me the reason for this error (caused by @RequiredArgsConstructor(onConstructor = @__(@Autowired)) to be exact) was a duplicated @Transactional annotation in another class (overlooked after rebasing a branch in Git). Removing the duplicate resolved the issue immediately, maybe this piece of information helps somebody in the future :-)

Brochu answered 3/2, 2023 at 12:44 Comment(0)
E
0

None of the answers that are written worked for me, and I don't think the answers are directly relevant to what OP alluded to is the main problem (which was my main problem as well).

I was trying to make the JavaDocs integration work with SpringDoc in a Spring Boot application I had. With the example given in the SpringDoc documentation itself, things didn't really work and I got the error that OP got.

Googling around a bit more, I found this StackOverflow answer

Following it, I just added the following to my pom.xml to make things work:

Add the following to your dependency:

    <dependency>
        <groupId>com.github.therapi</groupId>
        <artifactId>therapi-runtime-javadoc</artifactId>
        <version>0.15.0</version>
    </dependency>

Then add the following plugin to your <build> section

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <annotationProcessorPaths>
                    <path>
                        <groupId>com.github.therapi</groupId>
                        <artifactId>therapi-runtime-javadoc-scribe</artifactId>
                        <version>0.15.0</version>
                    </path>
                    <path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>${lombok.version}</version>
                    </path>
                </annotationProcessorPaths>
            </configuration>
        </plugin>
Eley answered 5/12, 2023 at 0:2 Comment(0)
B
0

I faced this problem many times. Here is a possible solution for Gradle.
Along with enabling Annotation Processing, try setting Gradle JVM property (see screenshot).
Also don't forget about SDK settings from Project Structure. Probably Java version and SDK you use in your project should be the same as the one used by Gradle.

I think for Maven the solution should be similar.

enter image description here

Bosworth answered 25/4 at 12:0 Comment(0)
K
0

For me the reason was missing testAnnotationProcessor 'org.projectlombok:lombok' in Gradle

Krypton answered 20/8 at 18:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.