2009-12-09 63 views
5

我正在運行一個項目,它依賴於groovy 1.7-beta-1。 gmaven插件使用groovy版本1.6作爲依賴。然而,當我運行Maven在調試模式下我看到了Groovy 1.6中被用於依賴於gmaven插件maven dependencies groovy

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

:在我的POM,我在依賴管理部分指定grooyv,所有版本。我認爲我的依賴管理部分會覆蓋這個,所以他們都使用1.7-beta-1,但由於不同的groovy版本,我得到錯誤。任何幫助在這裏將不勝感激。

感謝,

傑夫

回答

6

下面是帕斯卡答案的精煉版本。我將主插件版本升級到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> 
+0

我剛剛向原型插件提交了一個補丁,以便Maven central將獲得對org.codehaus.gmaven的新引用:gmaven-插件:1.2而不是它現在指向的2008版本。 – 2009-12-13 19:24:29

+0

問題鏈接在JIRA是這裏,所以你可以按照它的時間被接受http://jira.codehaus.org/browse/ARCHETYPE-272 請在JIRA中投票它,所以人們注意到它。 – 2009-12-13 19:33:07

+1

你可能會想要在配置中添加providerSelection = 1.7,並且在瞬態groovy上添加一個排除 - 全爲1。7-beta按照這裏提供的答案:http://stackoverflow.com/questions/2199547/maven-compile-mixed-java-groovy-1-7-project-using-gmaven-plugin/2221752#2221752 – Tim 2010-02-08 18:26:29

0

你需要一個類似的1.7依賴增加了插件的依賴關係類似結構的<plugin><pluginManagement>部分。您正在添加的依賴項管理部分是正確的,但不會影響插件依賴項。我會試着回顧一下這個回覆,稍後當我回到我的辦公桌時發佈一個例子。

+0

謝謝,馬修在此期間,我更新。新的gmaven插件確實解決了這個問題,但肯定不是最簡單的方法 – 2009-12-09 21:28:34

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兼容的新版插件(即可能將其用作依賴項),這就是你所做的。

1

爲了使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> 
相關問題