12

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>
Ian Lim
  • 4,164
  • 3
  • 29
  • 43
  • 2
    This isn't a duplicate, as it happens under Maven. The original ticket is for IntelliJ – nickcodefresh Feb 22 '16 at 11:18
  • For somebody who is looking for a solution like me: I found a solution at http://stackoverflow.com/questions/11329965/how-to-ignore-the-java-source-directory-during-maven-compilation – Ian Lim Feb 25 '16 at 01:47
  • This Q is totally unrelated to the "duplicate" Q and was incorrectly flagged. – stickfigure Sep 27 '19 at 21:36

4 Answers4

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>
Ahmad Abdelghany
  • 11,983
  • 5
  • 41
  • 36
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

Felipe Sabino
  • 17,825
  • 6
  • 78
  • 112
0

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

enter image description here

  • If you have a new question, please ask it by clicking the [Ask Question](https://stackoverflow.com/questions/ask) button. Include a link to this question if it helps provide context. - [From Review](/review/late-answers/32303614) – Guus Jul 25 '22 at 14:40
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 :-)

Theta
  • 231
  • 2
  • 14