lombok.config ignored when using groovy-eclipse-compiler
I'm not entirely sure if this is an issue or something with my settings, but when following the guidance here on getting groovy-eclipse-compiler to work with lombok, my lombok.config file seems to get ignored (I've tried moving it around to no avail).
For example, if I add lombok.log.fieldName = LOG to the lombok.config and update my source code accordingly, everything will work fine in eclipse but running mvn clean compile will lead to the following error:
[ERROR] LOG.debug("test");
[ERROR] ^^^
[ERROR] LOG cannot be resolved
using maven-compiler-plugin without the groovy-eclipse-compiler seems to work fine. what could be going on here?
How is the config file normally discovered/referenced? Can you provide a quick sample class for your LOG example?
I'm not sure how it works internally, but you can place the lombok.config file in any directory and it will basically apply the settings to everything in that directory or below. There is a brief description of the feature here.
And here is my sample to reproduce the error: https://github.com/rougou/lomboktest/blob/master/src/main/java/sample/Application.java
I should add everything appears fine in Eclipse IDE itself, but when I run mvn clean compile manually the error appears.
Do you have a working version of the same that uses the Eclipse Java compiler (ecj)? I can get it to work with Javac, but there is a step in between Javac and Groovy-Eclipse-Compiler (aka ecj). If it works for ecj, then the issue lies with greclipse, but if not, ecj or lombok needs to do something.
Do you mean using plexus-compiler-eclipse? I found that in that case, lombok doesn't work at all unless you set the jvm argument (-javaagent:path/to/lombok.jar) for the whole process. Something about it not accepting the fork argument. And even then lombok.config still has no effect (my sample project will fail).
This differs from groovy-eclipse-compiler where lombok itself works, but the config isn't applied.
Without maven, ECJ does work and pick up the lombok.config when used as below:
java -javaagent:lombok.jar=ECJ -jar ecj.jar -cp lombok.jar -source 1.8 (rest of arguments)
(see https://projectlombok.org/setup/ecj)
Sorry, this is a complex issue so it is difficult for me to be clear. What I am looking for is a Maven project that uses the eclipse batch compiler (if such a thing is possible) and produces the correct compilation. I tried a Maven version of the project you created with the standard Javac compiler to see that working correctly. And I can see that the groovy-eclipse adapter does not work. But it is hard to see where the problem truly lies with so many moving parts.
The groovy-eclipse adapter and batch compiler are very thin facades to the Eclipse ecj batch compiler. I suspect that this issue is with the Maven and ecj communication.
Yeh, so far I haven't gotten any flavor of ecj to work via Maven. Lombok's setup guide for ecj as linked above also fails to recognize the lombok.config, so I have posted an issue there as well.
Could you ask the lombok project if there are any arguments or system properties that control recognition of the config file? Their documents really don't help troubleshoot since they basically say "put these files anywhere and they will be found." Ecj passes arguments to the annotation processors using the "-A" command line option.
Any updates on this issue? I have a similar issue where the lombok configurations are not considered from the lombok.config file when using groovy-eclipse-compiler. Here is the maven compile configuration:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.2-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.4.3-01</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
</dependency>
</dependencies>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<verbose>true</verbose>
<fork>true</fork>
<compilerArguments>
<javaAgentClass>lombok.launch.Agent</javaAgentClass>
</compilerArguments>
</configuration>
</plugin>
Sorry, more examples are not needed. I do not think the Eclipse compiler (ecj) is reading this file when run from within Maven. You will need to raise awareness with Lombok, since there is nothing in the documentation that helps understand how the config files are actually located.
I have the same problem. Is there a potential work-around?
Related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=530665
@bureku That issue claims to have been fixed in Eclipse 4.8 (Photon).
Could you ask the lombok project if there are any arguments or system properties that control recognition of the config file?
FYI, I just opened a pull request in the lombok repo which adds a system property that allows you to pass a config file to lombok explicitly, see https://github.com/rzwitserloot/lombok/pull/2643
Is there any update on this issue? If this functionality was introduced in Lombok, a lot of projects could use Spock together with Java.
I am able to run the examples from https://github.com/projectlombok/lombok/issues/1501#issuecomment-341155220 / https://github.com/rougou/lomboktest with some updates.
This is my pom for ecj-config and ecj-noconfig. For it to work -- as stated in the linked comment -- maven needs to set the javaagent. The easiest way I found for doing this is to add .mvn/jvm.config with -javaagent:/path/to/lombok.jar=ECJ as its contents. There is a recent attempt to simplify and make this portable: https://github.com/jopatai/lombok-maven-ecj-bootstrap
<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>rougou.lomboktest</groupId>
<artifactId>ecj-config</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
<lombok.version>1.18.22</lombok.version>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.source>${java.version}</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<compilerId>eclipse</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
This is my pom for using tycho instead of plexus -- it needs similar bootstrapping of javaagent. But otherwise, it performed the same. It does not support a forked compile process.
<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>rougou.lomboktest</groupId>
<artifactId>jdt-noconfig</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
<lombok.version>1.18.22</lombok.version>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.source>${java.version}</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<compilerId>jdt</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-jdt</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
And this is my pom for groovy-eclipse-batch / groovy-eclipse-compiler. They support forked compilation, so no bootstrapping issues. The lombok.config is not found. When I try and debug, I get into lombok's shadow classes, which makes it really difficult to set breakpoints in advance and try to work out how the config is loaded.
<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>rougou.lomboktest</groupId>
<artifactId>groovy-eclipse-config</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
<lombok.version>1.18.22</lombok.version>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.source>${java.version}</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<pluginRepositories>
<pluginRepository>
<id>groovy-plugins-release</id>
<url>https://groovy.jfrog.io/artifactory/plugins-release</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<compilerArguments>
<javaAgentClass>lombok.launch.Agent</javaAgentClass>
<XprintRounds/>
</compilerArguments>
<fork>true</fork>
<verbose>true</verbose>
<compilerArgs>
<arg>-J-Xdebug</arg>
<arg>-J-Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=y</arg>
</compilerArgs>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>3.7.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>4.0.1-02</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
If this functionality was introduced in Lombok, a lot of projects could use Spock together with Java.
So lombok does integrate with the groovy joint compiler. It is just lombok.config that is missed. If you can go without that you are all set.
Also, if you goal is to have lombok support for main classes and groovy support for test classes, you can configure separate compilation for main and test, like this -- just stitch in lombok for main compile as usual:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>groovy-eclipse-maven-test</artifactId>
<groupId>org.codehaus.groovy</groupId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.fork>true</maven.compiler.fork>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>US-ASCII</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
<version>4.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-test</artifactId>
<version>4.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>2.2-M1-groovy-4.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.groovy</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin><!-- no need for this if your project also has src/test/java -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>add-test-source</id>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/groovy</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<!-- main compile options -->
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>3.7.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>4.0.1-01</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>groovy-plugins-release</id>
<url>https://groovy.jfrog.io/artifactory/plugins-release</url>
</pluginRepository>
</pluginRepositories>
</project>