0

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.

Keegan
  • 11,345
  • 1
  • 25
  • 38
GreenGiant
  • 4,930
  • 1
  • 46
  • 76

1 Answers1

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.

Keegan
  • 11,345
  • 1
  • 25
  • 38
  • That's disappointing :( Looks like I'm stuck at Groovy 1.5 until I can move to Maven 3. – GreenGiant May 29 '14 at 21:05
  • Sorry to revive an old question, but @Keegan: are there any examples of using GMavenPlus and the Annotations method to create Mojos? We have working versions using GMaven but management isn't fond of using abandoned projects. We want to use GMavenPlus but we're having a beast of a time getting one to work x) – medge Apr 30 '15 at 15:20
  • 1
    You can use my integration test as an example: https://github.com/groovy/GMavenPlus/tree/master/src/it/mavenPlugin. I need to find a better way to point people there. You're not the first person to ask this. Maybe I'll link it on the examples page. – Keegan Apr 30 '15 at 15:29
  • @Keegan: Have you ever run into an issue expanding project.basedir in the mojo Parameter annotation? Ex: (SO won't let me use the at sign) Parameter(defaultValue = "${project.basedir}/src/main/resources/target.template") String template... Groovy fails saying it is expecting an inline constant – medge Jun 23 '15 at 19:26
  • 1
    @MattEdge Just use single quotes instead of double quotes so that it gets past Groovy's GString expansion and gives Maven a chance to expand. – Keegan Jun 23 '15 at 21:35
  • @Keegan I am very sad and very happy that it was that simple of a fix x) Thanks! – medge Jun 23 '15 at 21:51