Lombok maven plugin

Lombok maven plugin DEFAULT

How to configure Lombok with maven-compiler-plugin?

I have a root module and submodule in maven in the project. I am trying to use Lombok. I have added

to root pom.xml. In submodule I have a class with Lombok annotations. When I am trying to build the project I get a lot of

cannot find symbol

where I am trying to call getters and setters.

I have tried to use lombok-maven-plugin with same version (1.16.12) in root pom and in the sub pom as well with delombok and moving my annotated class to src/main/lombok, I have looked through almost all questions in SO, try all the variants, but not succeed.

I am using Maven 3, Java 8, maven-compiler-plugin with 3.6.1 version.

How should I configure the project to be able to use lombok? Or maybe I am doing smth wrong.

asked Feb 15 '17 at 18:30

O.ZaiatsO.Zaiats

64022 gold badges99 silver badges1515 bronze badges

Sours: https://stackoverflow.com/questions/42257379/how-to-configure-lombok-with-maven-compiler-plugin

This chart shows how much is this artifact used as a dependency in other Maven artifacts in Central repository and GitHub:


select version:


Add this snippet into pom.xml inside tag <project><build><plugins>:




goals:
lombok:delombok (phase: generate-sources)

Delombok java source with lombok annotations.

lombok:help

Display help information on lombok-maven-plugin. Call mvn lombok:help -Ddetail=true -Dgoal=<goal-name> to display parameter details.

lombok:testDelombok (phase: generate-test-sources)

Delombok java test source with lombok annotations.

Often used code snippets:

<plugin> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId> <configuration> <addOutputDirectory>false</addOutputDirectory> <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory> </configuration> </plugin>
<plugin> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId> <version>1.18.10.0</version> <executions> <execution> <goals> <goal>delombok</goal> </goals> <phase>generate-sources</phase> </execution> </executions> </plugin>
<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>
<plugin> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId> <version>1.16.16.0</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>delombok</goal> </goals> <configuration> <encoding>UTF-8</encoding> <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory> <addOutputDirectory>false</addOutputDirectory> <verbose>true</verbose> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>sun.jdk</groupId> <artifactId>tools</artifactId> <version>1.8</version> <scope>system</scope> <systemPath>${java.home}/../lib/tools.jar</systemPath> </dependency> </dependencies> </plugin>
<plugin> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId> <version>1.18.6.0</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>delombok</goal> </goals> </execution> </executions> </plugin>

© Jiri Pinkas 2015 - 2021. All rights reserved. Admin login To submit bugs / feature requests please use this github page
related: JavaVids | Top Java Blogs | Java školení
Apache and Apache Maven are trademarks of the Apache Software Foundation. The Central Repository is a service mark of Sonatype, Inc.

Sours: https://javalibs.com/plugin/org.projectlombok/lombok-maven-plugin
  1. Cigars internationa
  2. Lighted nissan emblem
  3. Kaley cuoco iphone
  4. Jetta cooling fan
  5. Horizon house hatboro

Delomboking – delombok maven configuration Example

Using Project Lombok annotations in your POJOs will generates boilerplate code automatically at compile time. Delombok with maven plugin configuration provides a way to check how the compiled code looks like, becausethe actual code available in files, which is not directly visible for the developer. Delomboking helps in learning phase to understand how your compiled classes looks like and also helps to get back your actual POJOs if would like to move out of it later.

1. Maven configuration for delombok

1.1. Following is the complete maven configuration in pom.xml. You need to configure and make sure you already installed lombok setup for your IDE. To Setup in Eclipse or in Spring Tool Suite refer to our Lombok Maven example setup with Eclipse.

<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.javabydeveloper</groupId> <artifactId>delombok-tutorial</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>delombok-maven-example</name> <url>http://maven.apache.org</url> <properties> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <lombokSource>${project.basedir}/src/main/java/com/javabydeveloper/lombok</lombokSource> </properties> <dependencies> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.10</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic --> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> </dependency> </dependencies> <profiles> <profile> <id>dlombok</id> <build> <plugins> <plugin> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId> <version>1.18.12.0</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>delombok</goal> </goals> </execution> </executions> <configuration> <sourceDirectory>${lombokSource}</sourceDirectory> <verbose>true</verbose> <formatPreferences> <generateDelombokComment>skip</generateDelombokComment> <javaLangAsFQN>skip</javaLangAsFQN> <suppressWarnings>skip</suppressWarnings> </formatPreferences> </configuration> </plugin> </plugins> </build> </profile> </profiles> </project>

1.2. configuration property to provide the location where your lombok related classes. It always good to keep under separate package all Lombok related classes, it’s easier to check and maintain delomboked code.

1.3. is for delomboking your source code in phase and we would need to use delombok goal name to generate delomboking code for your lomboked classes.

1.4. We need to configure and run in a separate profile otherwise while generating sources main build will fail .

2. Delombok maven example Project Structure

Following is the project structure used in example application for delomboking code with maven.

delombok maven example

3. Generate Delombok code

3.1. To generate delombok code with above configuration, run the goal with profile. Following is the maven command.

3.2. Console Results :

[INFO] Scanning for projects... [INFO] [INFO] ---------------< com.javabydeveloper:delombok-tutorial >---------------- [INFO] Building delombok-maven-example 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ delombok-tutorial --- [INFO] Deleting \Workspaces\Lombok\delombok-maven-example\target [INFO] [INFO] --- lombok-maven-plugin:1.18.12.0:delombok (default-cli) @ delombok-tutorial --- File: \Workspaces\Lombok\delombok-maven-example\src\main\java\com\javabydeveloper\lombok\data\User.java [delomboked] File: \Workspaces\Lombok\delombok-maven-example\src\main\java\com\javabydeveloper\lombok\nonnull\LombokNonNullDemo1.java [delomboked] File: \Workspaces\Lombok\delombok-maven-example\src\main\java\com\javabydeveloper\lombok\settergetter\User.java [delomboked] File: \Workspaces\Lombok\delombok-maven-example\src\main\java\com\javabydeveloper\lombok\User.java [delomboked] [INFO] Delombok complete. [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 7.810 s [INFO] Finished at: 2020-05-16T13:01:10+08:00 [INFO] ------------------------------------------------------------------------

Build will be success and you can see delomboked code in “generated-sources” directory under “target” folder.

4. Example DeLomboked code

4.1. Lomboked User.java

To know about @Data annotation you can refer our tutorial Lombok Data annotation Examples.

@Data public class User { private Long id; private String username; }

4.2. DeLomboked User.java

public class User { private Long id; private String username; public User() { } public Long getId() { return this.id; } public String getUsername() { return this.username; } public void setId(final Long id) { this.id = id; } public void setUsername(final String username) { this.username = username; } @Override public boolean equals(final Object o) { if (o == this) return true; if (!(o instanceof User)) return false; final User other = (User) o; if (!other.canEqual((Object) this)) return false; final Object this$id = this.getId(); final Object other$id = other.getId(); if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; final Object this$username = this.getUsername(); final Object other$username = other.getUsername(); if (this$username == null ? other$username != null : !this$username.equals(other$username)) return false; return true; } protected boolean canEqual(final Object other) { return other instanceof User; } @Override public int hashCode() { final int PRIME = 59; int result = 1; final Object $id = this.getId(); result = result * PRIME + ($id == null ? 43 : $id.hashCode()); final Object $username = this.getUsername(); result = result * PRIME + ($username == null ? 43 : $username.hashCode()); return result; } @Override public String toString() { return "User(id=" + this.getId() + ", username=" + this.getUsername() + ")"; } }

5. Conclusion

In this article we have covered how to delombok your lombok code using maven configuration with an delombok maven example.

You can checkout source code from our github repository.

You might be interested in our other following Lombok Tutorials :

  1. Lombok @Getters / @Setters
  2. Lombok @ToString
  3. Lombok @EqualsAndHashCode
  4. Lombok @AllArgsConstructor
  5. Lombok @NoArgsConstructor
  6. Lombok @RequiredArgsConstructor
  7. Lombok @NonNull
  8. Lombok Spring Boot example

6. References

  1. Usage Guide
  2. Plugin Configuration
Sours: https://javabydeveloper.com/delomboking-delombok-maven-configuration-example/
How to resolve Maven Dependency Conflict? - Tech Primers

To set up lombok with any build tool, you have to specify that the lombok dependency is required to compile your source code, but does not need to be present when running/testing/jarring/otherwise deploying your code. Generally this is called a 'provided' dependency. This page explains how to integrate lombok with the Apache Maven build tool.

Lombok is available in maven central, so telling Maven to download lombok is easy.

Adding lombok to your pom file

To include lombok as a 'provided' dependency, add it to your block like so:

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

JDK9+ with module-info.java

The configuration of the compiler plug-in should contain the following:

<annotationProcessorPaths> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.22</version> </path> </annotationProcessorPaths>

Delomboking: The Lombok Maven Plugin

There is a plugin for Maven that we recommend you use if you want to delombok via maven. Useful if you want to run source analysis tools on your source after lombok has been applied, or if you want to generate javadoc. The plugin is open source. Read more about the lombok maven plugin.

Sours: https://projectlombok.org/setup/maven

Plugin lombok maven

Frequently Asked Questions

General

  1. Does one need to use the lombok-maven-plugin in order to use lombok in a maven project?
  2. What is the difference between maven-lombok-plugin and lombok-maven-plugin?
  3. Rather than placing source code in src/main/lombok, is there a way to delombok src/main/java code?
  4. Can one use lombok-pg extensions?
  5. Can one suppress PMD for generated methods?

Versions

  1. What version of lombok.jar is used by the plugin?
  2. Can the version of lombok.jar be overridden?

General

Does one need to use the lombok-maven-plugin in order to use lombok in a maven project?

No. The lombok-maven-plugin provides some goals that may assist lombok users, but it is not required.

One can use lombok with maven by adding the following to the pom.xml:

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

Note that lombok requires Java 6, so an explicit declaration of 1.6 compatibility to the compiler may also be required:

<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <compilerVersion>1.6</compilerVersion> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build>

[top]


What is the difference between maven-lombok-plugin and lombok-maven-plugin?

The first incarnation of this plugin was labeled maven-lombok-plugin, and was built using 0.9.3 of Project Lombok.

When the plugin was revised to support 0.10.0, the plugin was renamed to follow the Maven Plugin Naming Conventions. According to the convention, maven-lombok-plugin implies that it has a groupId of org.apache.maven.plugins; since it does not, lombok-maven-plugin is more appropriate.

[top]


Rather than placing source code in src/main/lombok, is there a way to delombok src/main/java code?

This is a common request, and yes there is a way to configure Maven to achieve this desired behavior. Please be advised that this strategy may have some negative consequences.

Delombok still operates as a code generator, but the src/main/java code is your delombok source (rather than src/main/lombok) and you need to override Maven's source directory to be target/generated-sources/delombok (rather than src/main/java).

<build> <sourceDirectory>target/generated-sources/delombok</sourceDirectory> <testSourceDirectory>target/generated-test-sources/delombok</testSourceDirectory> <plugin> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId> <version>1.18.20.0</version> <executions> <execution> <id>delombok</id> <phase>generate-sources</phase> <goals> <goal>delombok</goal> </goals> <configuration> <addOutputDirectory>false</addOutputDirectory> <sourceDirectory>src/main/java</sourceDirectory> </configuration> </execution> <execution> <id>test-delombok</id> <phase>generate-test-sources</phase> <goals> <goal>testDelombok</goal> </goals> <configuration> <addOutputDirectory>false</addOutputDirectory> <sourceDirectory>src/test/java</sourceDirectory> </configuration> </execution> </executions> </plugin> </build>

The discussion on Stack Overflow may be helpful.

[top]


Can one use lombok-pg extensions?

Yes -- as long as you are not using Java 7 (see lombok-pg issue 143). Simply add the lombok-pg artifact as a dependency to the plugin declaration. For example:

<build> <plugin> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId> <version>1.18.20.0</version> <dependencies> <dependency> <groupId>com.github.peichhorn</groupId> <artifactId>lombok-pg</artifactId> <version>0.11.3</version> </dependency> </dependencies> </plugin> </build>

Based on the lack of recent activity in the lombok-pg project, using those extensions is not recommended as you may run into future compatibility issues.

[top]


Can one suppress PMD for generated methods?

PMD is supposed to be skipping elements that are annotated with . If delombok fully qualifies the annotation as , then PMD may fail to skip it. PMD 5.1 fixed this bug.

The easiest way to get PMD to behave properly is to configure delombok to not fully qualify references. For example:

<build> <plugin> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId> <version>1.18.20.0</version> <executions> <execution> <id>delombok</id> <phase>generate-sources</phase> <goals> <goal>delombok</goal> </goals> <configuration> <formatPreferences> <javaLangAsFQN>skip</javaLangAsFQN> </formatPreferences> </configuration> </executions> </plugin> </build>

Another strategy with PMD 5, is that one can disable a rule using the Violation Suppress XPath mechanism. This used to be demonstrated by the Sample project, but it has since been removed because it is no longer necessary. You can read more about this strategy here.

[top]

Versions

What version of lombok.jar is used by the plugin?

Please refer to the Project Dependencies page.

[top]


Can the version of lombok.jar be overridden?

Yes. Maven 2.0.9 introduced the ability to override a dependency used by a plugin. For example:

<build> <plugin> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId> <version>1.18.20.0</version> <dependencies> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>0.99</version> </dependency> </dependencies> </plugin> </build>

The above example uses a newer version of the lombok.jar than what is defined for the plugin. But please note that the Delombok interface will need to be consistent; if not, then this will not work. For example, plugin changes were required to support 0.10.0-RC1 from 0.9.3 because Delombok had changed and was not fully backwards compatible from an interface perspective. Another incompatibility was introduced (shadow class loading) with version 1.16.0.

[top]

Sours: http://anthonywhitford.com/lombok.maven/lombok-maven-plugin/faq.html
Project Lombok - GoodBye Boilerplate Code

Oh-oh-oh. How many pathogens there are. Warm May days.

You will also be interested:

Man. Young and tall. With light brown hair. He appeared in Isabelle's dreams, somehow suddenly and from that moment they became inseparable, and the dreams became more and more realistic.



1667 1668 1669 1670 1671