6

In my POM I have this dependency

<dependencies>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>0.10.0-RC1</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

Now I'm trying to use this in the Maven exec plugin like this:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2</version>
            <executions>
                <execution>
                    <id>delombok-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <executable>java</executable>
                <arguments>
                    <argument>-classpath</argument>
                    <classpath>
                        <dependency>org.projectlombok:lombok</dependency>
                    </classpath>
                    <argument>lombok.core.Main</argument>
                    <argument>delombok</argument>
                    <argument>src/main/java</argument>
                    <argument>-d</argument>
                    <argument>target/src-delomboked</argument>
                </arguments>
            </configuration>
        </plugin>

But every time I execute exec:exec, I get a "java.lang.NoClassDefFoundError: lombok/core/Main" error. Some testing showed that this is because the dependency is declared in the provided scope

Why can't the exec plugin use provided dependencies? Second, is there any way for the exec plugin to use that dependency without changing the dependency scope?

TheLQ
  • 14,830
  • 14
  • 69
  • 107

3 Answers3

9

Found out the answer later: Simply add this to your config

<classpathScope>compile</classpathScope>

In hindsight this makes sense as lombok is a compile time annotation processor, not a runtime dependency.

TheLQ
  • 14,830
  • 14
  • 69
  • 107
3

In case someone is wondering how to do this without modifying the pom, you can add the following option to your command : -Dexec.classpathScope="compile"

For instance, i'm using:

mvn compile exec:java -Dexec.mainClass="my.package.MyMainClass" -Dexec.classpathScope="compile"
Crystark
  • 3,693
  • 5
  • 40
  • 61
  • This won't solve the problem if you also require runtime dependencies. What I wish the exec plugin provided was a more flexible scope declaration like 'provided+runtime' – wytten Mar 18 '14 at 15:25
  • I wished for the same feature and so I added it. http://jira.codehaus.org/browse/MEXEC-124. Unfortunately they haven't accepted it yet. – jgibson May 02 '15 at 17:46
  • @jgibson I made a replacement issue for your JIRA on their new Github repo, since Codehaus was shut down: https://github.com/mojohaus/exec-maven-plugin/issues/60 – Shannon Jul 27 '16 at 23:49
1

You may be interested in the lombok-maven-plugin, instead of trying to use the exec-maven-plugin.

AWhitford
  • 3,708
  • 3
  • 28
  • 38
  • This question was asked before lombok-maven-plugin had updated to 0.10.0. See https://github.com/awhitford/lombok.maven/issues/2 – TheLQ Sep 15 '11 at 14:15