【问题标题】:maven dependencies groovymaven 依赖 groovy
【发布时间】:2010-12-24 23:31:06
【问题描述】:

我正在运行一个依赖于 groovy 1.7-beta-1 的项目。 gmaven 插件使用 groovy 版本 1.6 作为依赖项。在我的 pom 中,我在依赖管理部分将 grooyv-all 版本指定为:

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

然而,当我在调试模式下运行 maven 时,我看到 groovy 1.6 被用于对 gmaven 插件的依赖。我以为我的依赖管理部分会覆盖它,所以它们都使用 1.7-beta-1,但是由于不同的 groovy 版本,我遇到了错误。如有任何帮助,我们将不胜感激。

谢谢,

杰夫

【问题讨论】:

    标签: maven-2 groovy dependencies dependency-management


    【解决方案1】:

    这是帕斯卡答案的精炼版本。我将主插件版本升级到 1.2,将依赖项升级到 Groovy 1.7,并将其全部包装在一个 pluginManagement 标记中,这样它就可以很好地利用继承模型。

    请记住,GMaven 插件的 1.3-SNAPSHOT 已经开始使用 1.7-rc2 Groovy 提供程序。

    <!-- 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>
    

    【讨论】:

    • 我刚刚向原型插件提交了一个补丁,以便 Maven 中心将获得对 org.codehaus.gmaven:gmaven-plugin:1.2 的新引用,而不是它现在指向的 2008 版。
    • JIRA 中的问题链接在这里,因此您可以关注它何时被接受jira.codehaus.org/browse/ARCHETYPE-272 请在 JIRA 中投票,以便人们注意到它。
    • 您可能希望在配置中添加 providerSelection = 1.7,并根据此处提供的答案排除瞬态 groovy-all 1.7-beta:stackoverflow.com/questions/2199547/…
    • 当前版本至少是 2.2.1 以防万一这里的版本不包含您需要的类(在我升级到 jasperreports 5.5.0 时发生在我身上)
    【解决方案2】:

    覆盖插件使用的依赖项是 Maven 2.0.9 实际上引入的一项不错的功能。

    为此,至少使用您用作普通构建插件的插件 - 而不是gmaven-plugin 的报告,所以我不会在这里介绍这种情况 - 只需添加插件块内的依赖块,如下所示(这是一个示例,因此版本可能不准确):

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

    只要新版本的依赖项与插件链接的版本“API 兼容”,就可以了。如果没有,那么您显然必须升级到与新 API 兼容的新版本插件(即可能将其用作依赖项),这就是您所做的。

    【讨论】:

      【解决方案3】:

      要让 gmaven 准确选择正确的运行时,可以通过配置“providerSelection”值,例如

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

      仅供参考,对于groovy:providers mojo,这些是它所期望的配置(我通过调试将它们提取到org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(List, Stack, MavenSession, MavenProject)(查找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>
      

      【讨论】:

        【解决方案4】:

        您需要在类似结构的&lt;plugin&gt;&lt;pluginManagement&gt; 部分中为插件的依赖项添加类似的1.7 依赖项。您添加的依赖项管理部分是正确的,但不会影响插件依赖项。当我回到办公桌后,我会尝试查看此回复并发布一个示例。

        【讨论】:

        • 谢谢,马修。与此同时,我更新了新的 gmaven 插件,它确实“修复”了这个问题,但肯定不是最干净的方法。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-22
        • 2019-09-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多