Maven exec plugin can't depend on provided dependancy?
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>
<arg开发者_如何学Cument>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?
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.
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"
You may be interested in the lombok-maven-plugin, instead of trying to use the exec-maven-plugin.
精彩评论