Creating Maven plugin written in Groovy 1.8

ⅰ亾dé卋堺 提交于 2019-12-11 19:35:36

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/23919556/creating-maven-plugin-written-in-groovy-1-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!