【问题标题】:Creating Maven plugin written in Groovy 1.8创建用 Groovy 1.8 编写的 Maven 插件
【发布时间】:2015-07-23 04:43:46
【问题描述】:

我正在尝试使用 groovy 创建一个 maven 插件。我想使用 groovy 1.8 或更高版本。

我已经关注了these instructions,如果我使用的话,一切都会顺利进行:

<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.0-rc-4</version>

这构建了我的插件,我可以在其他项目中使用它。

但是,这提供了旧版本的 groovy (1.5.7)。要切换到较新版本,我尝试使用新版本和 providerSelection:

<plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <version>1.5</version>
    <executions>
        <execution>
            <goals>
                <goal>generateStubs</goal>
                <goal>compile</goal>
                <goal>generateTestStubs</goal>
                <goal>testCompile</goal>
            </goals>
            <configuration>
                <providerSelection>1.8</providerSelection>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.gmaven.runtime</groupId>
            <artifactId>gmaven-runtime-1.8</artifactId>
            <version>1.5</version>
            <exclusions>
                <exclusion>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-all</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>1.8.0</version>
            <scope>compile</scope> 
        </dependency>
    </dependencies>
</plugin>

但是当我构建我的插件时,我收到了警告:

[WARNING] Deprecation Alert:
[WARNING] No mojo descriptors were found in this project which has a packaging type of maven-plugin.
[WARNING] In future versions of the plugin tools, this will fail the build.
[WARNING] If this project is an archetype, change the packaging type from maven-plugin to maven-archetype.

当我尝试使用我的插件时,maven 根本不会调用我的插件;我猜这是因为缺少插件描述符。

有没有人能够使用 groovy 成功构建一个 1.8 或更高版本的 maven 插件?

PS:我也查看了 groovy-eclipse-compiler 插件而不是 gmaven,但我似乎总是收到上面的警告。

【问题讨论】:

    标签: maven groovy maven-plugin gmaven-plugin


    【解决方案1】:

    没错。如果您阅读the code,您会发现gmaven-mojo 被硬编码为使用Groovy 1.5。这样做是为了它可以为您的插件的潜在用户提供最大的兼容性(因为 Groovy 1.6 需要 Java 5 而 Groovy 2.3 需要 Java 6)。 GMaven 不再真正维护,所以不要指望它会改变(抱歉)。

    大多数工具(如 GMavenPlus Groovyc Ant 任务)不支持这一点的原因是 Groovy 的官方模型类不保留 Javadoc(它包含 Maven 2 的类注解标记)。 GMaven 通过在内部分叉 Groovy 的代码来解决这个问题。 Maven 的 Groovy-Eclipse 插件不支持这一点,因为它根本不创建存根,因此 Maven 2 没有任何东西可以用来进行布线。有趣的是,他们也 fork Groovy 的代码,但出于其他原因。

    这是您的选择:

    1. 使用 GMaven,但不要扩展 GroovyMojo,它被硬编码为使用 Groovy 1.5(我以前没有这样做过,所以我不能 100% 确定它会工作)。
    2. 分叉 GMaven 并更改 gmaven-mojo 的依赖项以使用您选择的 Groovy。
    3. 使用 Maven 3 及其新的 Java 5 annotations,并使用您选择的 GMavenPlusgroovyc via AntRun 构建您的项目(我试图帮助人们了解他们选择的工具 here)。李>

    如果你确实走 Maven 3 路线,你可能需要添加

    <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
    

    到您的 maven-plugin-plugin 配置。

    【讨论】:

    • 这令人失望 :( 看起来我一直停留在 Groovy 1.5 直到我可以迁移到 Maven 3。
    • 很抱歉再次提出一个老问题,但是@Keegan:有没有使用 GMavenPlus 和 Annotations 方法创建 Mojos 的示例?我们有使用 GMaven 的工作版本,但管理层不喜欢使用废弃的项目。我们想使用 GMavenPlus,但我们很难让 GMavenPlus 工作 x)
    • 您可以以我的集成测试为例:github.com/groovy/GMavenPlus/tree/master/src/it/mavenPlugin。我需要找到一种更好的方法来将人们指向那里。你不是第一个问这个的人。也许我会在示例页面上链接它。
    • @Keegan:你有没有遇到过在 mojo 参数注释中扩展 project.basedir 的问题?例如:(所以不会让我使用 at 符号) Parameter(defaultValue = "${project.basedir}/src/main/resources/target.template") 字符串模板... Groovy 失败说它期待一个内联常数
    • @MattEdge 只需使用单引号而不是双引号,这样它就可以通过 Groovy 的 GString 扩展并给 Maven 一个扩展的机会。
    猜你喜欢
    • 2010-10-11
    • 1970-01-01
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    • 2017-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多