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

时间:2018-04-10 15:03:00

标签: java spring maven lombok

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

arrays

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

<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>

我使用IntelliJ并且已经检查过&#34;启用注释处理&#34; (首选项 - &gt;构建,执行,部署 - &gt;编译器 - &gt;注释处理器)。

当我运行mvn clean install -e:

[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

2 个答案:

答案 0 :(得分:2)

仔细看看这一行

[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>

答案 1 :(得分:0)

这是我保留的项目中的pom.xml,从我的GitHub复制粘贴:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.lorescianatico</groupId>
<artifactId>driftcoin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>driftcoin</name>
<description>Driftcoin project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>de.flapdoodle.embed</groupId>
        <artifactId>de.flapdoodle.embed.mongo</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-test</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>24.0-jre</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

如您所见,Lombok被声明为可选依赖项,没有范围或版本。父pom是Spring引导父级的。父pom包含处理Lombok的所有设置。