-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[BUG] Delombok not Working with Modules #2829
Comments
I was about to create this exact issue! |
I did some tests using your example project but was unable to compile it. I had to add lombok to the compiler plugin annotation path as mentioned on the lombok setup page and move the content of the |
This didn't work for me, this is the command I wrote: |
Just so we're on the same page, I'm not looking for help on the pom file. It is configured according to the documentation for the lombok plugin, and if you remove or rename module-info.java, it works fine. Adding module-info.java causes the failure because, it appears, the lombok plugin (and to some extent, the Delombok class) isn't designed to support modules. Rawi's suggestion of moving all the source code to src/main/java defeats the purpose of the delombok - I don't want to delombok my entire code set (the classes in the example I provided are a small subset of my project). My current work-around is a hack to the lombok plugin to set sourcepath = sourceDirectory (src/main/lombok), which works because the Delombok class never sees the module-info class (see the command line version of this in the delombok script). This feels like a true hack, though. It seems like the plugin needs to support setting the module-path and the sourcepath for the Delombok class so you can execute the equivalent of the command line: java -jar lombok-1.18.20.jar delombok src/main/lombok -d target/generated-sources/delombok --module-path $cp --sourcepath src/main/java But that doesn't work, either. It generates errors like the following: C:\projects\delombok-example\src\main\lombok\org\larrick\datagen\data\Address.java:7: error: file should be on source path, or on patch path for module Adding src/main/lombok to the sourcepath argument seems to actually generate delomboked code, but still generates errors like: C:\projects\delombok-example\src\main\lombok\org\larrick\datagen\data\Address.java:9: error: package com.fasterxml.jackson.annotation is not visible |
@Auties00 There are two Edit: |
I've done as you said but some modules are still unresolved. |
@Auties00 That's not my example project. |
Yeah, I'm using a project I'm working on as an example. Using the method that @Rawi01 suggested fixes the issue partially as now most of the modules are correctly detected |
The issue is getting weird though as java detects all the modules from the module path while lombok misses some. Maybe a similar option to --add-modules should be provided? |
I've created a temporary fix:
|
Nice fix! |
Your fix doesn't work for me. I referenced your plugin in my project and it delomboked the source files, but it didn't tell the compiler about the new source directory (below is the compiler output): [INFO] Changes detected - recompiling the module! And I don't see this as a good long-term fix. It forces me to delombok my entire code set, which kind of defeats the purpose of delomboking. |
@Auties00 Hmm, weird, it should be able to find the modules. I will try to reproduce that one. |
@Rawi01 That's a fair question. I want to apologize upfront if I gave the impression that this was an urgent issue for me -- it's not. As I mentioned before I hacked the plugin code to make my scenario work. I started using the lombok plugin in my build process, using the recommended configuration, because it seemed to improve my code coverage metrics. When I modularized my project, it broke the delombok process (as I'm learning, introducing modules breaks a lot of things). Hence the bug report. Based on my investigation, I feel like the "correct" fix to this problem may include changes to the core Delombok class as well as the plugin (please see my 4 May 21 comment). Unfortunately I don't fully understand how the Delombok class uses the compiler to accomplish it's task so I can't provide any reasonable suggestions. |
you have to specify the new sources using maven's compiler plugin. There is an option named "compileSourceRoots", set that to the outputDirectory of my plugin and it will work |
Hi @bradleylarrick, @Auties00, |
Vishvik, |
it's 100% a bad solution, but it works for me. You can look at how i use in my Cobalt library. It's just not as fast as it should be as it delomboks each file separately to avoid the modules problem |
So is there a real good configuration to solve this problem now? Is it really a problem with lombok which means the lombok can't work with java module system? |
What is the workaround for this on gradle? I've been using the freefair plugin and ran into the same issue when upgrading to modules. I thought I could remove delombok but it is needed for javadoc and the javadoc jar is required for publishing to maven central. This is a real mess for me. |
Add lombok dependency to the annotation processor portion of the compiler plug in using I deploy a lot to maven central with Java docs this way |
@GedMarc I'm asking about gradle specifically in a multimodule project with module-info.java. Javadoc will fail for missing builder classes and other issues. Delombok needs to run before javadoc but with the freefair gradle plugin delombok fails as described above. I was wondering if there is a similar plugin to what @Auties00 created for maven on gradle. |
Yes for Javadoc that does happen, Gradle configures a bit differently but the structures, configurations and end result is near identical to Maven - @moaxcp
You would want to configure the additional dependencies portion to include the modules that are required during build or source-shading, The gradle equivalent looks like it would be The issue of adding dependencies for gradles Javadoc’s is by adding the classpath dependency, if not shading sources |
I think that I understood what is happening. Today, I got this problem with Inspecting the JARs' structure I found what is happening: |
The Lombok plugin and delombok are not working correctly with modules. I've created
a sample project at https://github.com/bradleylarrick/delombok-example.git.
I'm using Maven 3.8.1, Lombok 1.18.20 and JDK 11 (the same behavior exhibits with JDK 16).
Without the module-info.java file the delombok process works correctly. When I add
the module-info.java file the lombok plugin errors saying that the modules referenced in
module-info.java can't be found:
src\main\java\module-info.java:24: error: module not found: com.fasterxml.jackson.annotation
src\main\java\module-info.java:25: error: module not found: com.fasterxml.jackson.core
.
.
.
I get the same errors when I try running the delombok from the command line using the same arguments
the plugin uses.
I can get the command line delombok to work if I change the sourcepath to point to the lombok-enabled
code (src/main/lombok) instead if the standard code (src/main/java). This presents the problem of
requiring all classes the lombok-enabled code reference to be in the src/main/lombok path.
I tried changing the command line script to add the jar files to the module-path instead of the classpath,
but then I get the following errors on the lombok-enabled classes:
C:\projects\delombok-example\src\main\lombok\org\larrick\datagen\data\Address.java:7: error: file should be on source path, or on patch path for module
C:\projects\delombok-example\src\main\lombok\org\larrick\datagen\data\Ethnicity.java:7: error: file should be on source path, or on patch path for module
.
.
.
Please advise.
The text was updated successfully, but these errors were encountered: