6

I'm running a project that has a dependency on groovy 1.7-beta-1. The gmaven plugin uses groovy version 1.6 as a dependency. In my pom, I specify in the dependency management section the grooyv-all version as :

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>1.7-beta-1</version>
        </dependency>
    </dependencies>
</dependencyManagement>

Yet when I run maven in debug mode I see that groovy 1.6 is being used for a dependency to the gmaven plugin. I thought my dependency management section would override this so they all use 1.7-beta-1, but I'm getting errors due to the different groovy versions. any help here would be appreciated.

thanks,

Jeff

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406

4 Answers4

7

Here's a refined version of Pascal's answer. I upgraded the main plugin version to 1.2, the dependency to Groovy 1.7, and wrapped it all in a pluginManagement tag so that it will nicely leverage the inheritance model.

Keep in mind that the 1.3-SNAPSHOT of the GMaven plugin has already begun using the 1.7-rc2 Groovy provider.

<!-- I wrapped everything in a plugin management section so that this can be neatly inherited across all your poms -->
<pluginManagement>
  <plugins>
    <plugin>
      <groupId>org.codehaus.gmaven</groupId>
      <artifactId>gmaven-plugin</artifactId>
      <!-- Notice I upgraded it to 1.2 -->
      <!-- Details here http://repo1.maven.org/maven2/org/codehaus/gmaven/gmaven-plugin/1.2/gmaven-plugin-1.2.pom -->
      <version>1.2</version>
      <dependencies>
        <dependency>
          <groupId>org.codehaus.gmaven.runtime</groupId>
          <artifactId>gmaven-runtime-1.7</artifactId>
          <version>1.2</version>
        </dependency>
      </dependencies>
    </plugin>
  </plugins>
</pluginManagement>
Matthew McCullough
  • 17,160
  • 7
  • 39
  • 38
  • I just submitted a patch to the archetype plugin so that Maven central will get a new reference to the org.codehaus.gmaven:gmaven-plugin:1.2 instead of the 2008 edition it is pointing to now. – Matthew McCullough Dec 13 '09 at 19:24
  • Issue link in JIRA is here so you can follow along for when it gets accepted http://jira.codehaus.org/browse/ARCHETYPE-272 Please vote it up over in JIRA so folks notice it. – Matthew McCullough Dec 13 '09 at 19:33
  • 1
    You'd might want to add providerSelection = 1.7 in the configuration, and an exclude on the transient groovy-all 1.7-beta as per the answer provided here: http://stackoverflow.com/questions/2199547/maven-compile-mixed-java-groovy-1-7-project-using-gmaven-plugin/2221752#2221752 – Tim Feb 08 '10 at 18:26
  • Current version is at least 2.2.1 just in case the version here does not contain a class you need (happened to me as I upgraded to jasperreports 5.5.0) – Yashima Feb 02 '14 at 14:57
2

Overriding a dependency used by a plugin is a nice ability that was actually introduced by Maven 2.0.9.

To do so, at least with a plugin that you are using as a normal build plugin - as opposed to a report which is not the case with the the gmaven-plugin so I won't cover this case here - simply add a dependency block inside the plugin block, like this (this is a sample so versions may be inaccurate):

<plugin>
  <groupId>org.codehaus.groovy.maven</groupId>
  <artifactId>gmaven-plugin</artifactId>
  <version>1.0</version>
  <executions>
    <execution>
      <goals>
        <goal>generateStubs</goal>
        <goal>compile</goal>
        <goal>generateTestStubs</goal>
        <goal>testCompile</goal>
      </goals>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-all</artifactId>
      <version>1.7-beta-1</version>
    </dependency>
  </dependencies>
</plugin>

As long as the new version of the dependency is "API compatible" with the version the plugin was linked against, you should be ok. If not, then you'll obviously have to upgrade to a newer version of the plugin compatible with the new API (i.e. likely using it as dependency), which is what you did.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
1

To make gmaven accurately picks the right runtime is by configuring the "providerSelection" value, e.g.

<plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
             <configuration>
                 <providerSelection>1.7</providerSelection>
             </configuration>

FYI, for the groovy:providers mojo, these are the configurations it expects (I extracted them by debugging to org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(List, Stack, MavenSession, MavenProject) (look for XmlPlexusConfiguration):

<configuration>
 <remoteRepositories implementation="java.util.List">${project.pluginArtifactRepositories}</remoteRepositories>
 <project implementation="org.apache.maven.project.MavenProject">${project}</project>
 <artifactRepository implementation="org.apache.maven.artifact.repository.ArtifactRepository">${localRepository}</artifactRepository>
 <pluginArtifactMap implementation="java.util.Map">${plugin.artifactMap}</pluginArtifactMap>
 <providerSelection implementation="java.lang.String">${gmaven.runtime}</providerSelection>
</configuration>
yclian
  • 1,490
  • 14
  • 22
0

You need to add a similar 1.7 dependency to the dependencies of the plugin in a similarly structured <plugin> or <pluginManagement> section. Your dependency management section you are adding is proper, but does not affect the plugin dependencies. I'll try to review this reply and post an example later when I'm back at my desk.

Matthew McCullough
  • 17,160
  • 7
  • 39
  • 38
  • Thanks, Matthew. In the meantime, I updated to the new gmaven plugin which did "fix" the issue but certainly not the cleanest way to do it. – Jeff Storey Dec 09 '09 at 21:28