1
votes

I use vs code and have already installed "Lombok Annotations Support for VS Code". I use maven clear and then compile, and I got Compilation failure. Then when I try maven compile several seconds later, it build success. I do nothing between two maven compilation.
I check the error message, it seems that Lombok annotations don't work.
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) [ERROR] symbol: method setName(java.lang.String)

[ERROR] symbol: method setCustomerUrl ERROR] required: no arguments

And when it build success, I got message

[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ withjpa ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ withjpa ---
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS   

And my pom.xml is

        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version> <!-- or newer version -->
                <configuration>
                    <source>1.8</source> <!-- depending on your project -->
                    <target>1.8</target> <!-- depending on your project -->
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${org.mapstruct.version}</version>
                        </path>  

I am wondering that I should change the plugin version to old version ? But when I change it to 3.1.0 there is CoreException.
Here is my repo : https://github.com/lyl156/backend/blob/master/src/main/java/com/example/withjpa/domain/Category.java

2
It may be something like a compiler vs runtime list of jars in your classpath. One of them may be missing. Maybe there's a pattern between the build lifecycle and the error you can investigate further.JGFMK

2 Answers

0
votes

Try this:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                        <annotationProcessorPaths>
                            <path>
                                <groupId>org.mapstruct</groupId>
                                <artifactId>mapstruct-processor</artifactId>
                                <version>${org.mapstruct.version}</version>
                            </path>
                            <path>
                                <groupId>org.projectlombok</groupId>
                                <artifactId>lombok</artifactId>
                                <version>${lombok.version}</version>
                            </path>
                        </annotationProcessorPaths>
                        <compilerArgs>
                            <compilerArg>
                                -Amapstruct.defaultComponentModel=spring
                            </compilerArg>
                        </compilerArgs>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

see also:

0
votes

Lombok does byte code manipulation under the covers while compiling.

One of the compilers in play here does not have Lombok support added to it, so the manipulation is not done. You have a compiler in your IDE and a compiler at the command line, which both output to the same location.

I would venture that you didn't follow https://projectlombok.org/setup/maven yet.