Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delombok sources in src/main/java rather than src/main/lombok #7

Open
tafit3 opened this issue Dec 17, 2011 · 19 comments
Open

delombok sources in src/main/java rather than src/main/lombok #7

tafit3 opened this issue Dec 17, 2011 · 19 comments

Comments

@tafit3
Copy link

tafit3 commented Dec 17, 2011

I have all the java sources in src/main/java directory. I want to be able to delombok them without changing the directory to src/main/lombok. I tried to use sourceDirectory parameter by setting it to "src/main/java", but I get a lot of "duplicate class" errors. I think the errors appear, because maven is trying to build from src/main/java and target/generated-sources/delombok at the same time.

Would it be possible to add a configuration parameter that would delombok the source code in src/main/java directory and continue the compilation only with the generated sources (ie. omitting original src/main/java)?

@awhitford
Copy link
Owner

The "duplicate class" issue is precisely the reason why lombok code is segregated into its own source tree.

However, I think you should be able to work around your issue by essentially telling Maven that your source is not in src/main/java; you can do this by adjusting the

<build>
    <sourceDirectory>src/main/java</sourceDirectory>
    ...
</build>

in your pom.

Alternatively, the maven-compiler-plugin configuration may be hacked to avoid compiling src/main/java AND target/generated-source/delombok. I think if you configure the value with a -sourcepath directive, that would do the trick.

(Perhaps I can try this later to prove it. Feel free to beat me to it.)

@tafit3
Copy link
Author

tafit3 commented Dec 18, 2011

I tried your suggestion and it works:

<sourceDirectory>target/generated-sources/delombok</sourceDirectory>

The above will cause src/main/java to be omitted from compilation. There is no "duplicate class" error. Of course I need to remember to set the sourceDirectory parameter of lombok-maven-plugin to "${project.basedir}/src/main/java".

I couldn't make the maven-compiler-plugin to exclude src/main/java from -sourcepath directive. The excludes option seems to affect only files and directories inside src/main/java (or inside other source compile paths). Maybe you have meant some other configuration, I couldn't find it.

The workaround you suggested is ok. I just tested it on the simple example project. I plan to test your workaround on a bigger project and I will report if I have any problems applying it.

However, the issue is still valid. If you have a project without lombok-maven-plugin and at some point you decide to include lombok-maven-plugin, you shouldn't be forced to go through all the maven modules you have and replace the directory name from "java" to "lombok". The "duplicate class" issue is hardly the reason for creating such a convetion. The convention stems from the fact that delombok is acting as source code generator, while it actually doesn't "generate" the source code. Delombok "transforms" the source code. Let me give you a simple example:

I have a project that uses cxf-xjc-plugin that generates some java source files and places them in the directory target/generated-sources/xsdtojava. The java files use lombok. The project uses another external tool that processes java source files and the external tool cannot handle lombok. So at this point I decide to add lombok-maven-plugin to delombok source files from directories: src/main/java and target/generated-sources/xsdtojava. If I want to use your workaround, I can't set sourceDirectory to both directories. Maybe there is some way of specifying two directories for delombok goal. I couldn't find any at

http://awhitford.github.com/lombok.maven/maven-lombok-plugin/delombok-mojo.html

Actually it is not important, if there is a possibility to specify two source directories, because it would be just another workaround. I am not familiar with the maven build process, so I don't know how to describe what would be the good solution or if it is even feasible, but it seems to me that delombok goal should be executed after source code generation and before compilation. I know delombok is itself source code generator, but it differs from other generators in that it does not "add" sources, but rather "replaces" them. This is what my issue is about.

Is implementing delombok as the source code generator the only way to go, given current possibilities in the maven project model and build process?

What is your opinion on the issue?

@awhitford
Copy link
Owner

I understand the frustration, but options are limited. Fundamentally, delombok is acting like a source code generator; as much as you may want to think of it as a transformer, it is really a generator -- it is just that the input is Java-like (sometimes valid Java, sometimes not), and the output is Java.

Certainly, if you want to fine-tune maven plugins to run at various phases, or even multiple times, you can do that. That is really a function of Maven: http://maven.apache.org/guides/mini/guide-configuring-plugins.html#Using_the_executions_Tag
So I think you can tweak your pom to deal with the cxf+lombok problem by executing delombok first, then executing the cxf action against the delombok output.

@fommil
Copy link

fommil commented Jul 4, 2012

I'd also like to see this problem addressed in future releases - maybe the trick documented here could be the default? (Or the default way to suggest that people install the plugin)

@fommil
Copy link

fommil commented Jul 4, 2012

Argh - using the target/generated-sources/delombok hack results in Netbeans thinking there is no Java source code for the project. Any hints on how to get around that?

@fommil
Copy link

fommil commented Jul 4, 2012

I've started a discussion on Stack Overflow about this to see if anyone with more Maven experience has anything to say: http://stackoverflow.com/questions/11329965

@fommil
Copy link

fommil commented Jul 11, 2012

I've also submitted an RFE with Maven to support the proposed "profile" solution

http://jira.codehaus.org/browse/MNG-5310

@TheLQ
Copy link

TheLQ commented Aug 13, 2012

Setting addOutputDirectory to false in the configuration seems to of fixed this issue

See http://stackoverflow.com/a/11930955/342518 for more information

@awhitford
Copy link
Owner

I recently responded to Issue #17 which is very similar.

One needs to:

  1. Override the default <build><sourceDirectory> from src/main/java to be ${project.build.directory}/generated-sources/delombok.
  2. Override the default delombok sourceDirectory from src/main/lombok to be src/main/java, and disable addOutputDirectory.

Basically, you will use src/main/java, but Maven will ignore it and instead use target/generated-sources/delombok. The Lombok plugin will transform src/main/java into elaborated code in target/generated-sources/delombok.

  <build>
    <sourceDirectory>${project.build.directory}/generated-sources/delombok</sourceDirectory>
    <plugins>
      <plugin>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok-maven-plugin</artifactId>
        <version>1.16.6.1</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>
        </executions>
      </plugin>
    </plugins>
  </build>

Use this hack at your own risk. (My guess is that this may confuse your IDE and some other developers.)

@thelaurg
Copy link

thelaurg commented Jun 9, 2017

This may work fine with main/java but I can not make the tests work with maven:

<build>
		<sourceDirectory>target/generated-sources/delombok</sourceDirectory>
		<testSourceDirectory>target/generated-test-sources/delombok</testSourceDirectory>
		<plugins>
			<plugin>
				<groupId>org.projectlombok</groupId>
				<artifactId>lombok-maven-plugin</artifactId>
				<version>1.16.14.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>
...

in lombok-maven-plugin:1.16.14.0:testDelombok (test-delombok) phase it can't find packages, symbols, so all unknown classes are replaced with java.lang.Object when using val, therefore compilation errors in test code. On this phase maven loses the classpath for sources, or should I set it explicitly? Maybe it looks for sources only in target/generated-test-sources/delombok not also in target/generated-sources/delombok.
Any thoughts?

@awhitford
Copy link
Owner

You may have better luck using ${project.build.directory} instead of target -- it may be important for a multi-module project.

If you still have issues, can you provide a small sample application that demonstrates this issue so that it can be further investigated?

@thelaurg
Copy link

Thanks @awhitford for your reply, but unfortunately it didn't work. Here is a small maven project to demonstrate that:
tdlbk.zip

As you will run mvn clean install you will see the error in the testDelombok phase:

[INFO] --- lombok-maven-plugin:1.16.14.0:testDelombok (test-delombok) @ tdlbk ---
C:\work\training\javaday\tdlbk\src\test\java\com\small\project\MyObjTest.java:13: error: Cannot use 'val' here because initializer expression does not have a representable type: Type cannot be resolved
        val myObj = new MyObj();
            ^
[INFO] Test Delombok complete.

and the delomboked test file:

        final java.lang.Object myObj = new MyObj();
        final com.small.project.MyObjFromT myObjT = new MyObjFromT();

MyObj is from sources and it is not solved at this phase.

awhitford added a commit that referenced this issue Aug 16, 2017
@awhitford
Copy link
Owner

awhitford commented Aug 16, 2017

Thank you @thelaurg for the unit test. I added something similar to my test project, was able to reproduce the problem, and then tweaked testDelombok to make it work. I have released version 1.16.18.1 with the fix. Please try that.

@c0demark
Copy link

@awhitford
I have a multi-module maven project where there is one parent project with packaging type pom and sub modules inside it with individual pom.xml files.

I was also facing the same issue of duplicate classes with maven build for lombok-maven-plugin. Then I came across this discussion thread and used the below configuration in my parent pom.xml file

			<plugin>
				<groupId>org.projectlombok</groupId>
				<artifactId>lombok-maven-plugin</artifactId>
				<version>1.16.20.0</version>
				<executions>
					<execution>
						<phase>generate-sources</phase>
						<goals>
							<goal>delombok</goal>
						</goals>
						<configuration>
							<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
							<addOutputDirectory>false</addOutputDirectory>
						</configuration>
					</execution>
				</executions>
			</plugin>

And I am able to do maven build successfully with maven 3.5.2 and jdk 1.8.
But now each sub module shows error in their pom.xml files. When I hover on the red error mark (which is on <parent tag) I get a error detail popup with the below content.

Execution default of goal org.projectlombok:lombok-maven-plugin:1.16.20.0:delombok failed: A required class was missing while executing org.projectlombok:lombok-maven-plugin:1.16.20.0:delombok: com/sun/tools/javac/tree/JCTree$JCCompilationUnit

realm = plugin>org.projectlombok:lombok-maven-plugin:1.16.20.0
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/Users/M1030469/.m2/repository/org/projectlombok/lombok-maven-plugin/1.16.20.0/lombok-maven-plugin-1.16.20.0.jar
urls[1] = file:/C:/Users/M1030469/.m2/repository/org/apache/commons/commons-lang3/3.7/commons-lang3-3.7.jar
urls[2] = file:/C:/Users/M1030469/.m2/repository/org/projectlombok/lombok/1.16.20/lombok-1.16.20.jar
urls[3] = file:/C:/Users/M1030469/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.8/plexus-utils-1.5.8.jar
Number of foreign imports: 5
import: Entry[import org.sonatype.plexus.build.incremental from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.Scanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.DirectoryScanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.AbstractScanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import from realm ClassRealm[maven.api, parent: null]]


(org.projectlombok:lombok-maven-plugin:1.16.20.0:delombok:default:generate-sources)

org.apache.maven.plugin.PluginExecutionException: Execution default of goal org.projectlombok:lombok-maven-plugin:1.16.20.0:delombok failed: A required class was missing while executing org.projectlombok:lombok-maven-plugin:1.16.20.0:delombok: com/sun/tools/javac/tree/JCTree$JCCompilationUnit

realm = plugin>org.projectlombok:lombok-maven-plugin:1.16.20.0
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/Users/M1030469/.m2/repository/org/projectlombok/lombok-maven-plugin/1.16.20.0/lombok-maven-plugin-1.16.20.0.jar
urls[1] = file:/C:/Users/M1030469/.m2/repository/org/apache/commons/commons-lang3/3.7/commons-lang3-3.7.jar
urls[2] = file:/C:/Users/M1030469/.m2/repository/org/projectlombok/lombok/1.16.20/lombok-1.16.20.jar
urls[3] = file:/C:/Users/M1030469/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.8/plexus-utils-1.5.8.jar
Number of foreign imports: 5
import: Entry[import org.sonatype.plexus.build.incremental from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.Scanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.DirectoryScanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.AbstractScanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import from realm ClassRealm[maven.api, parent: null]]


at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:168)
at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:331)
at org.eclipse.m2e.core.internal.embedder.MavenImpl$11.call(MavenImpl.java:1362)
at org.eclipse.m2e.core.internal.embedder.MavenImpl$11.call(MavenImpl.java:1)
at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176)
at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:112)
at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:1360)
at org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant.build(MojoExecutionBuildParticipant.java:52)
at org.eclipse.m2e.core.internal.builder.MavenBuilderImpl.build(MavenBuilderImpl.java:137)
at org.eclipse.m2e.core.internal.builder.MavenBuilder$1.method(MavenBuilder.java:172)
at org.eclipse.m2e.core.internal.builder.MavenBuilder$1.method(MavenBuilder.java:1)
at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod$1$1.call(MavenBuilder.java:115)
at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176)
at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:112)
at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod$1.call(MavenBuilder.java:105)
at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176)
at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:151)
at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:99)
at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.execute(MavenBuilder.java:86)
at org.eclipse.m2e.core.internal.builder.MavenBuilder.build(MavenBuilder.java:200)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:735)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:301)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:304)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:360)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:383)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:144)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

Caused by: org.apache.maven.plugin.PluginContainerException: A required class was missing while executing org.projectlombok:lombok-maven-plugin:1.16.20.0:delombok: com/sun/tools/javac/tree/JCTree$JCCompilationUnit

realm = plugin>org.projectlombok:lombok-maven-plugin:1.16.20.0
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/Users/M1030469/.m2/repository/org/projectlombok/lombok-maven-plugin/1.16.20.0/lombok-maven-plugin-1.16.20.0.jar
urls[1] = file:/C:/Users/M1030469/.m2/repository/org/apache/commons/commons-lang3/3.7/commons-lang3-3.7.jar
urls[2] = file:/C:/Users/M1030469/.m2/repository/org/projectlombok/lombok/1.16.20/lombok-1.16.20.jar
urls[3] = file:/C:/Users/M1030469/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.8/plexus-utils-1.5.8.jar
Number of foreign imports: 5
import: Entry[import org.sonatype.plexus.build.incremental from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.Scanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.DirectoryScanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.AbstractScanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import from realm ClassRealm[maven.api, parent: null]]


at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:166)
... 31 more

Caused by: java.lang.NoClassDefFoundError: com/sun/tools/javac/tree/JCTree$JCCompilationUnit
at lombok.delombok.Delombok.getModuleField(Delombok.java:482)
at lombok.delombok.Delombok.(Delombok.java:479)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at lombok.launch.Delombok.(Delombok.java:32)
at lombok.maven.AbstractDelombokMojo.execute(AbstractDelombokMojo.java:135)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 31 more
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.tree.JCTree$JCCompilationUnit
at java.lang.ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at lombok.launch.ShadowClassLoader.loadClass(ShadowClassLoader.java:422)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 41 more

I am making an educated guess that this might be a jdk incompatibilty issue as the plugin requirement as mentioned in lombok-maven-plugin doc is jdk 1.6 but I am using jdk 1.8. Please note that I cannot use jdk 1.6 as it is a spring boot project and needs jdk 1.8 only. Suggest any workaround or treat this as a friendly observation of issue and provide solution for it to work with jdk versions higher than 1.6.

@awhitford
Copy link
Owner

@c0demark I think I will need more information about your scenario. Your problem is stemming from Eclipse, not the command-line? Note that Lombok requires Oracle JDK or Open JDK -- if you have another JDK, that may not work (and there is nothing that I can do about that).

If you would like me to investigate further, please put together a sample project that exhibits the issue with reproduction steps.

@ruwanka
Copy link

ruwanka commented Jul 22, 2020

@awhitford I am getting error on java 11 although I set <sourceDirectory> to generated sources. It works on java 8. Any Idea?

@aSemy
Copy link

aSemy commented Apr 3, 2021

On a kind of related topic, I wanted to permanently delombok a large, multi-module project that had lombok and java code all in <project-dir>/src/main.

I hacked together this maven-antrun-plugin to...

  1. (before delombok runs) automatically copy all of src/main/java to src/main/lombok
  2. then after delombok is done,
    1. delete src/main/lombok
    2. copy the generated-sources/delombok to src/main/java (overwriting lombok files with delomboked ones)
    3. delete the generated delombok folder.

Maybe others find this useful :) If anything's unclear I can tidy up the source code a bit.

In the parent pom, I set:

  <build>
    <plugins>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
      </plugin>

      <plugin>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok-maven-plugin</artifactId>
        <version>1.18.20.0</version>
      </plugin>
    </plugins>

    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.8</version>
          <executions>
            <execution>
              <id>copy-src-to-lombok</id>
              <configuration>
                <target>
                  <echo>trying to copy from [${basedir}/src/main]</echo>
                  <echo>target: [${basedir}/src/main/lombok]</echo>
                  <mkdir dir="${basedir}/src/main/lombok"/>
                  <mkdir dir="${basedir}/src/main/java"/>
                  <copy todir="${basedir}/src/main/lombok">
                    <fileset dir="${basedir}/src/main/java" includes="**/*"/>
                  </copy>
                </target>
              </configuration>
              <phase>initialize</phase>
              <goals>
                <goal>run</goal>
              </goals>
            </execution>
            <execution>
              <id>replace-lombok-with-delombok</id>
              <configuration>
                <target>
                  <echo>removing lombok copy dir [${basedir}/src/main/lombok]</echo>
                  <delete dir="${basedir}/src/main/lombok"/>

                  <copy todir="${basedir}/src/main/java" failonerror="false">
                    <fileset dir="${basedir}/target/generated-sources/delombok"
                      includes="**/*java"/>
                  </copy>

                  <delete dir="${basedir}/target/generated-sources/delombok"/>
                </target>
              </configuration>
              <phase>process-sources</phase>
              <goals>
                <goal>run</goal>
              </goals>
            </execution>
          </executions>
        </plugin>

        <plugin>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok-maven-plugin</artifactId>
          <version>1.18.20.0</version>
          <executions>
            <execution>
              <phase>generate-sources</phase>
              <goals>
                <goal>delombok</goal>
              </goals>
            </execution>
          </executions>
          <configuration>
            <formatPreferences>
              <suppressWarnings>skip</suppressWarnings>
              <danceAroundIdeChecks>skip</danceAroundIdeChecks>
              <indent>2</indent>
              <generated>skip</generated>
            </formatPreferences>
            <outputDirectory>${basedir}/target/generated-sources/delombok</outputDirectory>
          </configuration>
        </plugin>

      </plugins>
    </pluginManagement>

@siqiniao
Copy link

I recently responded to Issue #17 which is very similar.

One needs to:

  1. Override the default <build><sourceDirectory> from src/main/java to be ${project.build.directory}/generated-sources/delombok.
  2. Override the default delombok sourceDirectory from src/main/lombok to be src/main/java, and disable addOutputDirectory.

Basically, you will use src/main/java, but Maven will ignore it and instead use target/generated-sources/delombok. The Lombok plugin will transform src/main/java into elaborated code in target/generated-sources/delombok.

  <build>
    <sourceDirectory>${project.build.directory}/generated-sources/delombok</sourceDirectory>
    <plugins>
      <plugin>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok-maven-plugin</artifactId>
        <version>1.16.6.1</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>
        </executions>
      </plugin>
    </plugins>
  </build>

Use this hack at your own risk. (My guess is that this may confuse your IDE and some other developers.)

not friendly to idea ....

@jonefeewang
Copy link

I finally use this method solve this problem gently! hope can help the other guys.
https://sudonull.com/post/1197-Lombok-sourcesjar-and-convenient-debug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants