maven compile sometimes fail and sometimes succeed

痴心易碎 提交于 2021-01-28 09:01:47

问题


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


回答1:


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:

  • https://mapstruct.org/faq/#Can-I-use-MapStruct-together-with-Project-Lombok
    • and linked sample



回答2:


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.



来源:https://stackoverflow.com/questions/62608302/maven-compile-sometimes-fail-and-sometimes-succeed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!