Is there a way to compile lomboked code in ECJ without setting lombok as javaaagent for the maven process?
The snippet below only works if I run mvn with lombok as agent
<profile>
<id>ecj</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerId>eclipse</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.8</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
MAVEN_OPTS=-javaagent:lombok.jar mvn -P ecj
results in successfull compilation.
However running just mvn -P ecj
spews the usual no-lombok errors like: __ cannot be resolved to a type
I tried using com.reubenpeeris.maven:lombok-eclipse-compiler:1.3
but this fails with Compilation failure
Unrecognized option: target/generated-sources/annotations
, which I think means this compiler is too old.
I also tried adding
<fork>true</fork>
<compilerArgs>
<arg>-javaagent:lombok.jar</arg>
</compilerArgs>
but it doesn't seem to have any effect.
In short, there is no way. However, there is wrokaround.
The eclipse implementation is
plexus-compiler-eclipse
, it doesn't acceptfork
argument, as it uses the internal jvm. So, it can only accept jvm options likeMAVEN_OPTS
.However, the default implementation is "plexus-compiler-javac", which supports custom
executable
. The workaround may like this: setfork
totrue
, and specify theexecutable
. It maybe like this:or, use the ecj from the project directly, define
-AJAVAC
in thepom.xml
: (-AXXX=XXX
is acceptable byjavac
)change the pom.xml:
Here is the best I was able to do without setting the javaagent for whole maven process: