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.6</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.6.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.6.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 @SuppressWarnings("all"). If delombok fully qualifies the annotation as @java.lang.SupressWarnings("all"), 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 java.lang references. For example:

<build>
  <plugin>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok-maven-plugin</artifactId>
    <version>1.18.6.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.6.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]