2012-06-28 59 views
32

近日,笔者来到翻过以下问题:Maven的依赖管理的插件依赖性

当我设置的依赖管理我的项目,我使用的插件与依赖,我想与依赖同步有孩子,聚甲醛在我的依赖管理中声明。

在根POM,我在我的依赖管理声明:

<dependencyManagement> 
    <dependencies> 
     ... 
     <dependency> 
      <groupId>com.google.gwt</groupId> 
      <artifactId>gwt-user</artifactId> 
      <version>2.4.0</version> 
     </dependency> 
     ... 
    <dependencies> 
<dependencyManagement> 

而且在孩子POM,我有需要GWT-用户插件:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>gwt-maven-plugin</artifactId> 
    <version>2.4.0</version> 
    <dependencies> 
     <dependency> 
      <groupId>com.google.gwt</groupId> 
      <artifactId>gwt-user</artifactId> 
      <version>2.4.0</version> 
     </dependency> 
      ... 
     </dependencies> 
    ... 
</plugin> 

但是,如果我删除gwt-maven-plugin中使用的依赖版本,编译失败。

是否有另一种方法来实现它?

PS:有一个相关的帖子Choosing dependency version in maven and maven plugin不回答我的问题

回答

36

按照以下链接,它似乎不是可能:

这里是一个解决办法,我发现,我想和大家一起分享,在情况下,其他人也有同样的问题:

在我的根源,我已经定义了一个属性,一个依赖管理和一个插件人agement:

<properties> 
    <gwtVersion>2.4.0</gwtVersion> 
    <gwtMavenPluginVersion>2.4.0</gwtMavenPluginVersion> 
</properties> 

<dependencyManagement> 
    <dependencies> 
    ... 
    <dependency> 
     <groupId>com.google.gwt</groupId> 
     <artifactId>gwt-user</artifactId> 
     <version>${gwtVersion}</version> 
    </dependency> 
    ... 
    <dependencies> 
<dependencyManagement> 

<build>  
    <pluginManagement> 
     <plugins> 
      <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>gwt-maven-plugin</artifactId> 
      <version>${gwtMavenPluginVersion}</version> 
      <dependencies> 
       <dependency> 
        <groupId>com.google.gwt</groupId> 
        <artifactId>gwt-user</artifactId> 
        <version>${gwtVersion}</version> 
       </dependency> 
       ... 
      </dependencies> 
      ... 
     </plugins> 
    ... 
    </pluginManagement> 
</build> 

而且在我的孩子聚甲醛,使用插件管理(见Maven2 - problem with pluginManagement and parent-child relationship)所提供的关系,我只是声明插件的依赖:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>gwt-maven-plugin</artifactId> 
</plugin> 

现在,如果我在属性更改版本它会自动影响所有直接依赖和插件依赖。

+0

恕我直言,如果只需要插件中的依赖关系,那么对于未来的引用,依赖关系管理部分 –

+3

就没有用处。 pluginManagement在构建标签下 – TecHunter

4

对于父POM来控制插件版本的儿童使用,应在父POM的<pluginManagement>部分申报<plugin>

您在<dependencyManagement>部分中将com.google.gwt:gwt-user定义为<dependency>

我不知道你是否打算使用gwt-user作为插件或依赖项,但它应该被列为两个工作继承的同一个实体。

+0

gwt-user被用作具有依赖关系的插件。 OP正在尝试仅在一个位置获取为两者定义的版本。 – eis

1

另一种可能性是导入父POM的所有依赖:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>gwt-maven-plugin</artifactId> 
    <version>2.4.0</version> 
    <dependencies> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>${project.artifactId}</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
      ... 
     </dependencies> 
    ... 
</plugin> 

不是最漂亮的解决方案,但我用的是码头Maven插件工作:-)

0

在我的案例,依赖于hsqldb。我从sonatype书中复制了一些示例行(我认为这是我从中得到的行),以便使用指定groupId为hsqldb的jetty插件。我正在使用hsqldb的版本2.3.2。在dependencyManagement部分和我的持久性模块中,我的父pom中的groupId是org.hsqldb。有不匹配的groupIds是什么导致我得到一个错误,因为在那个老的groupId下没有2.3.2版本。一旦我将groupId从hsqldb更改为org.hsqldb,一切都开始工作。