gpt4 book ai didi

java - Lombok 不适用于 spring-boot-maven-plugin

转载 作者:行者123 更新时间:2023-12-02 03:31:17 24 4
gpt4 key购买 nike

我有 Spring-boot 应用程序以及下一个插件和依赖项:

<!--...-->
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>


<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.8</version>
<scope>provided</scope>
</dependency>

<!--...-->

<build>
<finalName>service-api</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
<configuration>
<descriptors>
<descriptor>service-api.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.alexecollins.docker</groupId>
<artifactId>docker-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

以及在我的应用程序中测试 lombok 的文本 2 个类:

import lombok.Data;

@Data
public class TestDto {

private String testStr;
}

还有

   public class TestCall {

public void testLombok() {
TestDto dto = new TestDto();

dto.setTestStr("My Test String.");

System.out.println(dto);
}

}

因此,当我从插件运行 spring-boot:run 甚至是一个简单的命令 mvncompile 时,我遇到了下一个错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project service-api: Compilation failure: Compilation failure: [ERROR] D:\Projects\??????\service-api\src\main\java\TestCall.java:[7,-1] [ERROR] 1. ERROR in D:\Projects\???????\service-api\src\main\java\TestCall.java (at line 7) [ERROR] dto.setTestStr("My Test String."); [ERROR] ^^^^^^^^^^ [ERROR] The method setTestStr(String) is undefined for the type TestDto [ERROR] ---------- [ERROR] 1 problem (1 error) [ERROR] [ERROR] Found 1 error and 0 warnings.

似乎lombok 功能不适用于 spting 插件。但是,如果我使用标准 ma​​ven-compiler-plugin(版本 3.5.1),一切都会正常工作。但现在我们想使用 spring boot 嵌入式容器,并且我们还没有准备好改变我们的构建工作流程。是否可以针对这个问题做点什么?也许我应该包含一些特殊的依赖项或类似的东西?

最佳答案

问题出在包含下一个插件的父pom中:

  <pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.2-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.4.3-01</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>

所以,我在这里找到了解决方案:Maven Groovy and Java + Lombok

现在我的 groovy-eclipse-compiler 插件是:

    <pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<verbose>true</verbose>
<fork>true</fork>
<compilerArguments>
<javaAgentClass>lombok.launch.Agent</javaAgentClass>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.2-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.4.3-01</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.8</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>

关于java - Lombok 不适用于 spring-boot-maven-plugin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38052411/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com