创建用Groovy 1.8编写的Maven插件 [英] Creating Maven plugin written in Groovy 1.8

查看:168
本文介绍了创建用Groovy 1.8编写的Maven插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我遵循

 实现+ Maven +插件rel =nofollow>这些说明, <&的groupId GT; org.codehaus.groovy.maven< /&的groupId GT; 
< 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>
<执行次数>
<执行>
<目标>
< goal> generateStubs< / goal>
< goal>编译< / goal>
< goal> generateTestStubs< / goal>
< goal> testCompile< / goal>
< /目标>
<配置>
< providerSelection> 1.8< / providerSelection>
< / configuration>
< /执行>
< /执行次数>
<依赖关系>
< dependency>
< groupId> org.codehaus.gmaven.runtime< / groupId>
< artifactId> gmaven-runtime-1.8< / artifactId>
< version> 1.5< / version>
<排除项>
<排除>
< groupId> org.codehaus.groovy< / groupId>
< artifactId> groovy-all< / artifactId>
< /排除>
< /排除>
< /依赖关系>
< dependency>
< groupId> org.codehaus.groovy< / groupId>
< artifactId> groovy-all< / artifactId>
< version> 1.8.0< / version>
< scope>编译< / scope>
< /依赖关系>
< /依赖关系>
< / plugin>

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

  [警告]弃用警报:
[警告]在此项目中找不到含有maven-plugin的打包类型的mojo描述符。
[警告]在未来版本的插件工具中,这会使构建失败。
[警告]如果这个项目是一个原型,请将maven-plugin的包装类型更改为maven-archetype。

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



任何人都可以使用groovy成功构建maven插件,版本为1.8或更高版本?



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

解决方案

这是正确的。如果您阅读代码,您会发现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无法使用它进行连线。有趣的是,他们还分叉Groovy的代码,但出于其他原因。



以下是您的选择:


  1. 使用GMaven,但不扩展GroovyMojo,它使用Groovy 1.5进行硬编码(我之前没有这样做过,所以我不能100%确定它会起作用)。

  2. 分叉GMaven并更改gmaven-mojo的依赖关系以使用您选择的Groovy。
  3. 使用Maven 3及其新Java 5 annotations ,并用您选择的 GMavenPlus 通过AntRun的groovyc (我试图帮助人们了解他们对工具的选择 / rel =nofollow> rel =nofollow> rel =nofollow>这里)。

如果你真的去了Mave您可能需要添加

 < skipErrorNoDescriptorsFound> true< / skipErrorNoDescriptorsFound> 

添加到您的maven-plugin-plugin配置中。


I'm attempting to create a maven plugin using groovy. I'd like to use groovy version 1.8 or higher.

I've followed these instructions and got things working if I use:

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

This build my plugin and I'm able to use it in other projects.

However, this gives an older version of groovy (1.5.7). To switch to a newer version, I tried using a new version and 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>

But when I build my plugin, I get the warning:

[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.

And when I attempt to use my plugin, maven does not call my plugin at all; I'm guessing this is because of the missing plugin descriptors.

Has anyone been able to successfully build a maven plugin using groovy, with a version of 1.8 or higher?

PS: I also looked into the groovy-eclipse-compiler plugin instead of gmaven, but I seem to always get the warning above.

解决方案

That's correct. If you read the code, you'll find that the gmaven-mojo is hard-coded to use Groovy 1.5. This was done so that it could offer the greatest compatibility with potential users of your plugin (since Groovy 1.6 requires Java 5 and Groovy 2.3 requires Java 6). GMaven isn't really maintained anymore, so don't expect that to change (sorry).

The reason most tools (like the GMavenPlus Groovyc Ant task) don't support this is that Groovy's official model classes don't keep the Javadoc (which holds Maven 2's annotation-like markers). GMaven worked around this by forking Groovy's code internally. The Groovy-Eclipse plugin for Maven doesn't support this is that it doesn't create stubs at all so there's nothing for Maven 2 to use to do the wiring. Interestingly, they also fork Groovy's code, but for other reasons.

Here's your options:

  1. Use GMaven, but don't extend GroovyMojo, which was hard-coded to use Groovy 1.5 (I've not done this before, so I'm not 100% sure it'll work).
  2. Fork GMaven and change the dependency of gmaven-mojo to use the Groovy of your choice.
  3. Use Maven 3 and its new Java 5 annotations, and build your project with your choice of GMavenPlus or groovyc via AntRun (I've tried to help people understand their choice of tools here).

If you do go the Maven 3 route, you will probably need to add

<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>

to your maven-plugin-plugin configuration.

这篇关于创建用Groovy 1.8编写的Maven插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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