Maven exec插件不能依赖于提供的依赖关系吗? [英] Maven exec plugin can't depend on provided dependancy?

查看:129
本文介绍了Maven exec插件不能依赖于提供的依赖关系吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的POM中,我有这种依赖关系

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>

现在,我正在尝试在Maven exec插件中使用此代码,

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>

但是每次执行exec:exec时,都会出现"java.lang.NoClassDefFoundError:lombok/core/Main"错误.一些测试表明,这是因为在提供的范围中声明了依赖项

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

为什么exec插件不能使用提供的依赖项?其次,exec插件在不更改依赖范围的情况下可以使用该依赖吗?

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>

事后看来,这很有意义,因为lombok是编译时注释处理器,而不是运行时依赖项.

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

这篇关于Maven exec插件不能依赖于提供的依赖关系吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆