插件依赖关系的Maven依赖关系管理 [英] Maven dependency management for plugin dependencies

查看:129
本文介绍了插件依赖关系的Maven依赖关系管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我遇到了以下问题:



当我为我的项目设置依赖关系管理时,我使用了具有依赖关系的插件,这是我想要的与我的依赖关系管理中声明的依赖项同步。



在根pom中,我在我的依赖关系管理中声明:

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

在孩子pom中,我有一个需要gwt-user的插件:

 < 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中使用的依赖版本,则编译失败。 / p>

还有其他方法可以实现吗?



PS:有相关帖子选择maven和maven插件中的依赖版本,但不回答我的问题

解决方案

根据以下链接,似乎不可能:





这是我找到的一种解决方法,我想撒谎与大家一起讨论,以防其他人遇到同样的问题:



在我的root pom中,我定义了一个属性,一个依赖关系管理和一个插件管理:

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

在我的孩子pom中,使用插件管理提供的关系(参见 Maven2 - 插件管理和父子关系的问题),我只是声明插件依赖:

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

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


Recently, I came accross the following problem :

As I set up dependency management for my project, I had child-pom using plugin with dependencies, that I want to be synchronized with dependencies declared in my dependency management.

In a root pom, I declared in my dependency management:

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

And in the child pom, I have a plugin which needs gwt-user :

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

However, if I remove the dependency version used in gwt-maven-plugin, the compilation fails.

Is there another way to achieve it ?

PS: There is a related post Choosing dependency version in maven and maven plugin which does not answer my question

解决方案

According to the following links, it seems not to be possible :

Here is a workaround I found, and I wanted to share with everyone, in case other people had the same problem :

In my root pom, I have defined a property, a dependency management and a plugin management :

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

And in my child pom, using the relationship provided by plugin management (see Maven2 - problem with pluginManagement and parent-child relationship), I just declare the plugin dependency :

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

Now if I change the version in the properties, it is automatically impacting all direct dependencies and plugin dependencies.

这篇关于插件依赖关系的Maven依赖关系管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆