Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javadoc error on @RequiredArgsConstructor(onConstructor=@__(@Inject))

Tags:

java

lombok

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>
like image 710
Ian Lim Avatar asked Feb 19 '16 02:02

Ian Lim


People also ask

How do I fix Javadoc errors?

You need to call mvn javadoc:fix to fix main Java source files (i.e. inside src/main/java directory) or mvn javadoc:test-fix to fix test Java source files (i.e. inside src/test/java directory).

What is onConstructor @__ @inject?

For example, this: @RequiredArgsConstructor(onConstructor = @__(@Inject)) will generate a constructor annotated with @Inject. Follow this answer to receive notifications.


2 Answers

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>
like image 197
Ahmad Abdelghany Avatar answered Sep 17 '22 17:09

Ahmad Abdelghany


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

like image 21
Felipe Sabino Avatar answered Sep 17 '22 17:09

Felipe Sabino