java - 我在 Spring 项目中使用 Lombok 但 Maven 构建失败

标签 java spring maven lombok

我想将 Lombok 添加到我的 Spring 项目中。我正在使用 Maven,所以我将 lombok 依赖项放在我的 pom.xml 文件中。
这是我的 pom.xml 文件的依赖部分:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
            <version>2.0.1.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
            <!-- scope>test</scope-->
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>1.10.19</version>
        </dependency>
        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <version>1.4.01</version>
        </dependency>
        <dependency>
            <groupId>xmlunit</groupId>
            <artifactId>xmlunit</artifactId>
            <version>1.6</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <scope>test</scope>
            <version>2.44.0</version>
        </dependency>
        <dependency>
            <groupId>com.opera</groupId>
            <artifactId>operadriver</artifactId>
            <scope>test</scope>
            <version>1.5</version>
            <exclusions>
                <exclusion>
                    <groupId>org.seleniumhq.selenium</groupId>
                    <artifactId>selenium-remote-driver</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.codehaus.sonar-plugins.java/sonar-jacoco-listeners -->
        <dependency>
            <groupId>org.codehaus.sonar-plugins.java</groupId>
            <artifactId>sonar-jacoco-listeners</artifactId>
            <version>3.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/javax.mail/mail -->
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-test-autoconfigure</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.20</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

当我尝试使用“mvn clean install”运行maven时,构建失败,我找不到原因。这是日志:

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building project-management 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ project-management ---
[INFO] Deleting /Users/domingosmartins/git/switch-2017-g003/target
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.9:prepare-agent (default-prepare-agent) @ project-management ---
[INFO] argLine set to -javaagent:/Users/domingosmartins/.m2/repository/org/jacoco/org.jacoco.agent/0.7.9/org.jacoco.agent-0.7.9-runtime.jar=destfile=/Users/domingosmartins/git/switch-2017-g003/target/jacoco.exec
[INFO] 
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ project-management ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ project-management ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 138 source files to /Users/domingosmartins/git/switch-2017-g003/target/classes
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING : 
[INFO] -------------------------------------------------------------
[WARNING] No processor claimed any of these annotations: org.springframework.web.bind.annotation.PathVariable,org.springframework.beans.factory.annotation.Autowired,org.springframework.web.bind.annotation.RequestMapping,org.springframework.stereotype.Controller,org.springframework.web.bind.annotation.RequestBody,javax.persistence.Table,org.springframework.stereotype.Service,com.fasterxml.jackson.annotation.JsonIgnore,javax.persistence.Enumerated,org.springframework.web.bind.annotation.ExceptionHandler,org.springframework.stereotype.Repository,javax.persistence.ManyToMany,javax.persistence.Id,org.springframework.web.bind.annotation.ControllerAdvice,javax.persistence.Entity,javax.persistence.ManyToOne,com.fasterxml.jackson.annotation.JsonBackReference,org.springframework.boot.autoconfigure.SpringBootApplication,javax.transaction.Transactional,javax.persistence.JoinColumn,javax.persistence.OneToMany,org.springframework.web.bind.annotation.RestController,javax.persistence.OneToOne,javax.persistence.Column,org.springframework.stereotype.Component,javax.persistence.GeneratedValue,javax.persistence.Transient,javax.annotation.PostConstruct,org.springframework.web.bind.annotation.RequestHeader,com.fasterxml.jackson.annotation.JsonManagedReference
[INFO] 1 warning
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] warnings found and -Werror specified
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.878 s
[INFO] Finished at: 2018-04-10T15:16:57+01:00
[INFO] Final Memory: 36M/294M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project project-management: Compilation failure
[ERROR] warnings found and -Werror specified
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

我正在使用 IntelliJ,并且已经选中“启用注释处理”(首选项 -> 构建、执行、部署 -> 编译器 -> 注释处理器)。

当我运行 mvn clean install -e 时:

[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building project-management 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ project-management ---
[INFO] Deleting /Users/domingosmartins/git/switch-2017-g003/target
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.9:prepare-agent (default-prepare-agent) @ project-management ---
[INFO] argLine set to -javaagent:/Users/domingosmartins/.m2/repository/org/jacoco/org.jacoco.agent/0.7.9/org.jacoco.agent-0.7.9-runtime.jar=destfile=/Users/domingosmartins/git/switch-2017-g003/target/jacoco.exec
[INFO] 
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ project-management ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ project-management ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 138 source files to /Users/domingosmartins/git/switch-2017-g003/target/classes
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING : 
[INFO] -------------------------------------------------------------
[WARNING] No processor claimed any of these annotations: org.springframework.web.bind.annotation.PathVariable,org.springframework.beans.factory.annotation.Autowired,org.springframework.web.bind.annotation.RequestMapping,org.springframework.stereotype.Controller,org.springframework.web.bind.annotation.RequestBody,javax.persistence.Table,org.springframework.stereotype.Service,com.fasterxml.jackson.annotation.JsonIgnore,javax.persistence.Enumerated,org.springframework.web.bind.annotation.ExceptionHandler,org.springframework.stereotype.Repository,javax.persistence.ManyToMany,javax.persistence.Id,org.springframework.web.bind.annotation.ControllerAdvice,javax.persistence.Entity,javax.persistence.ManyToOne,com.fasterxml.jackson.annotation.JsonBackReference,org.springframework.boot.autoconfigure.SpringBootApplication,javax.transaction.Transactional,javax.persistence.JoinColumn,javax.persistence.OneToMany,org.springframework.web.bind.annotation.RestController,javax.persistence.OneToOne,javax.persistence.Column,org.springframework.stereotype.Component,javax.persistence.GeneratedValue,javax.persistence.Transient,javax.annotation.PostConstruct,org.springframework.web.bind.annotation.RequestHeader,com.fasterxml.jackson.annotation.JsonManagedReference
[INFO] 1 warning
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] warnings found and -Werror specified
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.603 s
[INFO] Finished at: 2018-04-12T01:06:27+01:00
[INFO] Final Memory: 36M/288M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project project-management: Compilation failure
[ERROR] warnings found and -Werror specified
[ERROR] 
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project project-management: Compilation failure
warnings found and -Werror specified

    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
warnings found and -Werror specified

    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1161)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:168)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

最佳答案

仔细看这一行

[WARNING] No processor claimed any of these annotations: org.springframework.web.bind.annotation.PathVariable,org.springframework.beans.factory.annotation.Autowired,org.springframework.web.bind.annotation.RequestMapping,org.springframework.stereotype.Controller,org.springframework.web.bind.annotation.RequestBody,javax.persistence.Table,org.springframework.stereotype.Service,com.fasterxml.jackson.annotation.JsonIgnore,javax.persistence.Enumerated,org.springframework.web.bind.annotation.ExceptionHandler,org.springframework.stereotype.Repository,javax.persistence.ManyToMany,javax.persistence.Id,org.springframework.web.bind.annotation.ControllerAdvice,javax.persistence.Entity,javax.persistence.ManyToOne,com.fasterxml.jackson.annotation.JsonBackReference,org.springframework.boot.autoconfigure.SpringBootApplication,javax.transaction.Transactional,javax.persistence.JoinColumn,javax.persistence.OneToMany,org.springframework.web.bind.annotation.RestController,javax.persistence.OneToOne,javax.persistence.Column,org.springframework.stereotype.Component,javax.persistence.GeneratedValue,javax.persistence.Transient,javax.annotation.PostConstruct,org.springframework.web.bind.annotation.RequestHeader,com.fasterxml.jackson.annotation.JsonManagedReference

您的 pom.xml 需要更多启动器

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

等等

关于java - 我在 Spring 项目中使用 Lombok 但 Maven 构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49757018/

相关文章:

spring - Maven/Spring 未正确运行 jmeter 测试

java - Spring boot配置文件同步maven配置文件

java - 子类化一个开源库

java - Eclipse android Maven : Plugin execution not covered by lifecycle configuration (execution: ndk- build,阶段:编译)

java - core-0.13.0.job.jar 丢失,我需要它

java - 使用 javascript 动态添加重复(唯一 ID)表单 Div 元素

java - Spring Boot Web 应用程序中的语言翻译

java - 如何为指定索引添加数组值而不替换它?

java - if-else 中的局部变量初始化问题(Java)

spring - Grails + Spring 安全核心 : How to assign a role after user has logged in?