Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

java - Maven dependency management for plugin dependencies

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...