Reputation: 360
I have Spring-boot application with the next plugins and dependencies:
<!--...-->
<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>
And the text 2 classes for testing lombok in my app:
import lombok.Data;
@Data
public class TestDto {
private String testStr;
}
And
public class TestCall {
public void testLombok() {
TestDto dto = new TestDto();
dto.setTestStr("My Test String.");
System.out.println(dto);
}
}
So, when I run spring-boot:run from the plugin or even a simple command mvn compile, I have the next error:
[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.
It seems the lombok features don't work on spting plugin. However if I use a standard maven-compiler-plugin(version 3.5.1) everything is working correctly. But for now we want to use spring boot embedded container and we are not ready to change our build workflow. Is it possible to do something with this issue? May be I should include some special dependencies or something like that?
Upvotes: 0
Views: 12609
Reputation: 603
If you are experiencing that by using IDE (like eclipse) -
This is the solution.
Install and run the lombok-ide jar from here
Upvotes: 0
Reputation: 360
The problem was in the parent pom that contains the next plugin:
<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>
So, I found the solution here: Maven Groovy and Java + Lombok
and now my groovy-eclipse-compiler plugin is:
<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>
Upvotes: 2
Reputation: 7496
As Lombok generates some boilerplate code so that you do not have to do it, there must be a means to initialize this generation. In the case of your IDE you have a plugin that will do that. However for a Maven build you require a build step that tells maven that the relevant code should be generated (within the build section):
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.16.8.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
</execution>
</executions>
</plugin>
For further details please check the documentation of the plugin.
Upvotes: 1