0

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?

eGoLai
  • 360
  • 1
  • 3
  • 16
  • 3
    generated a fresh boot (web + lombok) maven project via http://start.spring.io and put a simple lombok data class in it and it works just fine. https://gist.github.com/zapl/1d238b278b8cc68e330e4bf1048943a8 is the generated pom (untouched) and the java source (added the data class), `spring-boot:run` prints "hello" as expected. – zapl Jun 27 '16 at 11:32
  • 1
    The problem is that I have a parent pom with groovy-eclipse-compiler plugin. So I found how it should be configured for lombok in this topic: http://stackoverflow.com/questions/8524891/maven-groovy-and-java-lombok – eGoLai Jun 27 '16 at 12:37

3 Answers3

2

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>
Community
  • 1
  • 1
eGoLai
  • 360
  • 1
  • 3
  • 16
1

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.

hotzst
  • 7,238
  • 9
  • 41
  • 64
  • 1
    The plugin is not required if using a compiler that supports the JSR 269 Pluggable Annotation Processing API. Which si the standard way of using lombok. – Magnus Jun 27 '16 at 11:20
  • This plugin needed for generating expanded sources. I think adding an interim generated sources is a bad idea. As it's said on official web site I need only to have a lomok lib in the class pass during compiling the project: https://projectlombok.org/mavenrepo/index.html – eGoLai Jun 27 '16 at 11:34
0

If you are experiencing that by using IDE (like eclipse) -

This is the solution.

Install and run the lombok-ide jar from here

lingar
  • 477
  • 1
  • 7
  • 25