3

To compile my Java/Lombok-project after adding a Groovy class, I added this configuration to my pom.xml, as instructed on Maven Groovy and Java + Lombok:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</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>
    </dependencies>
    <configuration>
        <compilerId>groovy-eclipse-compiler</compilerId>
        <verbose>true</verbose>   
        <compilerArguments>
          <javaAgentClass>lombok.launch.Agent</javaAgentClass>
        </compilerArguments>
        <fork>true</fork>
    </configuration>
</plugin>
<plugin>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-eclipse-compiler</artifactId>
    <version>2.9.2-01</version>
    <extensions>true</extensions>
</plugin>

However, building then fails after this:

Fatal error compiling: Cannot find the requested className <lombok.launch.Agent> in classpath -> [Help 1]

When inspecting lombok-1.16.16.jar, it does contain a class called Agent inside the lombok/launch path, and the class path contains that jar file inside my .m2

Can someone tell me what I have to do to make my project build?

Mr. Wrong
  • 500
  • 7
  • 21
  • Can you post the rest of your `maven-compiler-plugin` XML? – Brian Mar 08 '18 at 18:52
  • I've added the xml for both compiler plugins. – Mr. Wrong Mar 08 '18 at 21:39
  • The question you linked has the Lombok `` inside the `` `` list. Have you tried that? – Brian Mar 09 '18 at 19:29
  • Yes, we've tried that, but to no avail. We also tried extending the Agent class inside our project, but it is not public. Could that be the reason the plugin can't find it? – Mr. Wrong Mar 10 '18 at 11:23
  • The only requirement is that the methods from the agent class (`premain`, for example) are `public` and `static`, and [Lombok does this correctly](https://github.com/rzwitserloot/lombok/blob/master/src/launch/lombok/launch/Agent.java#L29-L35). Java [uses the system classloader to load agent classes](https://docs.oracle.com/javase/7/docs/api/java/lang/instrument/package-summary.html). What happens if you run your build with Maven outside of Eclipse using the `mvn` command? – Brian Mar 12 '18 at 13:18
  • Right. The result is the same if we build from the command line using mvn clean install. – Mr. Wrong Mar 12 '18 at 16:17
  • We have the same issue – Robert Mikes Dec 26 '18 at 06:42
  • 2
    This solution solved it for me: https://stackoverflow.com/a/9948860/2969332 – Robert Mikes Dec 26 '18 at 06:47
  • You can find the correct answer here: https://stackoverflow.com/questions/8524891/maven-groovy-and-java-lombok. – mihai_f87 Jan 10 '19 at 12:23

0 Answers0