Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven exec plugin can't depend on provided dependancy?

Tags:

java

maven

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?

like image 290
TheLQ Avatar asked Jun 20 '11 22:06

TheLQ


Video Answer


1 Answers

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.

like image 133
TheLQ Avatar answered Oct 05 '22 22:10

TheLQ