Lombok and Maven
Asked Answered
N

7

39

I'm trying to use Lombok with Maven and VRaptor on IntelliJ but it doesn't work.

I already read some info in stackoverflow but none solved my problem, i already enabled the Annotation Processor in Intellij but still nothing.

I tryied to compile it from command-line too (Windows) and didn't work.

I also tryed to create another project without maven and add the library, create some classes for test and it works, compile and run perfectly.

Any help?

The project has only 2 class, 1 entity and 1 controller

Here is my pom.xml

<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>razor</groupId>
<artifactId>controle-de-ponto</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>

<description>Um sistema de controlo de ponto</description>

<repositories>
    <repository>
        <id>projectlombok.org</id>
        <url>http://projectlombok.org/mavenrepo</url>
    </repository>
</repositories>

<properties>
    <project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
    <weld.version>2.1.2.Final</weld.version>
</properties>

<dependencies>
    <dependency>
        <groupId>br.com.caelum</groupId>
        <artifactId>vraptor</artifactId>
        <version>4.1.4</version>
    </dependency>

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

    <dependency>
        <groupId>org.jboss.weld.servlet</groupId>
        <artifactId>weld-servlet-core</artifactId>
        <version>2.1.2.Final</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.weld</groupId>
        <artifactId>weld-core-impl</artifactId>
        <version>2.1.2.Final</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.el</groupId>
        <artifactId>el-api</artifactId>
        <version>2.2</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator-cdi</artifactId>
        <version>5.1.1.Final</version>
    </dependency>

    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
        <!-- uncomment this line on app servers -->
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.velocity</groupId>
        <artifactId>velocity</artifactId>
        <version>1.7</version>
    </dependency>

    <dependency>
        <groupId>org.apache.velocity</groupId>
        <artifactId>velocity-tools</artifactId>
        <version>2.0</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.8.Final</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.34</version>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>br.com.caelum.vraptor</groupId>
        <artifactId>vraptor-jpa</artifactId>
        <version>4.0.2</version>
    </dependency>

    <dependency>
        <groupId>br.com.caelum.vraptor</groupId>
        <artifactId>vraptor-java8</artifactId>
        <version>4.0.0.Final</version>
    </dependency>
</dependencies>

<build>
    <finalName>controle-de-ponto</finalName>
    <!--<outputDirectory>/Users/turini/Documents/workspace/vraptor4/vraptor-blank-project/src/main/webapp/WEB-INF/classes</outputDirectory>-->
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <compilerVersion>1.8</compilerVersion>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Error when i try to compile:

[INFO] ------------------------------------------------------------------------
[INFO] Building controle-de-ponto 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ controle-de-ponto ---
[INFO] Using 'ISO-8859-1' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ controle-de-ponto ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\Users\Kennedy\Desktop\controle-de-ponto\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/Kennedy/Desktop/controle-de-ponto/src/main/java/br/com/caelum/vraptor/controller/IndexController.java:[37,16] cannot find symbol
  symbol:   method setNome(java.lang.String)
  location: variable usuario of type org.razor.cponto.beans.Usuario
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.167 s
[INFO] Finished at: 2015-02-04T13:41:01-02:00
[INFO] Final Memory: 17M/204M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project controle-de-ponto: Compilation failure
[ERROR] /C:/Users/Kennedy/Desktop/controle-de-ponto/src/main/java/br/com/caelum/vraptor/controller/IndexController.java:[37,16] cannot find symbol
[ERROR] symbol:   method setNome(java.lang.String)
[ERROR] location: variable usuario of type org.razor.cponto.beans.Usuario
[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
Nonary answered 4/2, 2015 at 15:36 Comment(6)
Could you be more specific than "it didn't work"? What was the error?Chastain
I edited my question with more info.Nonary
the Usuario class has the annotation @Data. And the setNome is generated by it.Nonary
@Chastain i added more info.Nonary
I wonder if they made it possible to work with any IDE that is not Eclipse.Triumvirate
i'l try to same project on eclipse to see if it builds.Nonary
A
15

This should work as is, and has nothing to do with IntelliJ idea. But I would:

  • make sure the @Data annotation is the lombok one
  • remove the repository definition (maven central is fine)
  • use a recent lombok version (1.16.0 as of this writing)
  • rebuild (mvn clean package)

I think the lombok jar is not found by maven in your case or that you might have another @Data.

Avery answered 4/2, 2015 at 16:26 Comment(3)
Thx! Looks like was the version, i didn't see i was using an old version. Shame on me haha.Nonary
It's more likely to be the repo: browse projectlombok.org/mavenrepo and you'll see it doesn't look like a maven repo.Avery
mvn clean package and then removing the old war file. Replacing with new one. And then after deployment. Bazinga :D +1Hilaryhilbert
A
80

This might work

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>1.16.12</version>
                    </path>                         
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    </plugins>
</build>

Latest versions:

Aneto answered 20/1, 2017 at 10:12 Comment(5)
Thanks, took me hours and your solution fixed it. Working with maven-compiler-plugin 3.6.2 and lombok 1.16.16Pintsize
This works, but unexpectedly moving lombok dependency to the beginning of <dependencies> list also helped. maven-compiler-plugin 3.7.0 lombok 1.18.0Sundsvall
According documentation this is for Java 9+ - projectlombok.org/setup/mavenRestrain
Opened my eyes. Thanks when I added another annotation processor (for map struct) lombok stopped working and I was not realising the issue being caused by the now missing implicit declaration of the annotation processor. Took me too many hours ...Avestan
Same issue as @KevinKussmaul ... it saved me !!Pullen
A
15

This should work as is, and has nothing to do with IntelliJ idea. But I would:

  • make sure the @Data annotation is the lombok one
  • remove the repository definition (maven central is fine)
  • use a recent lombok version (1.16.0 as of this writing)
  • rebuild (mvn clean package)

I think the lombok jar is not found by maven in your case or that you might have another @Data.

Avery answered 4/2, 2015 at 16:26 Comment(3)
Thx! Looks like was the version, i didn't see i was using an old version. Shame on me haha.Nonary
It's more likely to be the repo: browse projectlombok.org/mavenrepo and you'll see it doesn't look like a maven repo.Avery
mvn clean package and then removing the old war file. Replacing with new one. And then after deployment. Bazinga :D +1Hilaryhilbert
N
0

Try this dependency

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.16.16</version>
    <scope>provided</scope>
</dependency>
Nilson answered 11/6, 2018 at 1:25 Comment(0)
M
0

In the projectId tag, try to replace projectlombok.org with org.projectlombok

Masterson answered 8/8, 2021 at 1:40 Comment(0)
J
0

try this

org.projectlombok lombok 1.18.24
Jessalin answered 12/4 at 18:27 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Fructification
I
-1
<dependency>  
  <groupId>org.projectlombok</groupId> 
  <artifactId>lombok</artifactId> 
</dependency>

this should solve the problem same issue on my vs code

Inclinatory answered 22/12, 2021 at 21:42 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Fructification
B
-6

You need add lombok plugin:

  <build>
  <plugins>
    <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>
  </plugins>
</build>
Birdlime answered 17/5, 2016 at 13:28 Comment(1)
no, this is for replacing the Lombok annotations with equivalent source codeAneto

© 2022 - 2024 — McMap. All rights reserved.