Reputation: 95
I have encountered a problem with maven-dependency-plugin
(Maven version 3.2.3
, maven-dependency-plugin
version 2.10
). I am trying to introduce plugin dependencies. I created a simple project:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sze</groupId>
<artifactId>mvn-project</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.2</version>
</plugin>
</plugins>
</build>
</project>
I have chosen the maven-antrun-plugin version 1.2, cause this plugin and its dependencies were mentioned in the Maven Official Guide to Configuring Plug-ins. Then I run a command to resolve it's dependencies:
mvn dependency:resolve-plugins
The output:
[INFO] Plugin Resolved: maven-antrun-plugin-1.2.jar
[INFO] Plugin Dependency Resolved: maven-plugin-api-2.0.1.jar
[INFO] Plugin Dependency Resolved: maven-project-2.0.1.jar
[INFO] Plugin Dependency Resolved: ant-launcher-1.6.5.jar
[INFO] Plugin Dependency Resolved: ant-1.6.5.jar
Indeed, I have ant
and ant-launcher
version 1.6.5
. Now I want to change the version of these dependencies and change my pom.xml
:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sze</groupId>
<artifactId>mvn-project</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.2</version>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-launcher</artifactId>
<version>1.7.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
But when I run again mvn dependency:resolve-plugins
, the version of the dependencies that belong to the maven-antrun-plugin
is still 1.6.5
:
[INFO] Plugin Resolved: maven-antrun-plugin-1.2.jar
[INFO] Plugin Dependency Resolved: maven-plugin-api-2.0.1.jar
[INFO] Plugin Dependency Resolved: maven-project-2.0.1.jar
[INFO] Plugin Dependency Resolved: ant-launcher-1.6.5.jar
[INFO] Plugin Dependency Resolved: ant-1.6.5.jar
How else can I check that the version of these dependencies is changed?
Upvotes: 5
Views: 2676
Reputation: 7966
For some reason, the resolve-plugins
goal will not resolve custom plugin dependencies. If you want to see which plugins are actually used, you will have to run Maven in debug mode:
mvn -X antrun:run
This will show you the dependencies that are added to the classpath:
[DEBUG] org.apache.maven.plugins:maven-antrun-plugin:jar:1.2:
[DEBUG] org.apache.ant:ant:jar:1.7.1:runtime
[DEBUG] org.apache.ant:ant-launcher:jar:1.7.1:runtime
[DEBUG] org.apache.maven:maven-plugin-api:jar:2.0.1:compile
[DEBUG] org.apache.maven:maven-project:jar:2.0.1:compile
[DEBUG] org.apache.maven:maven-profile:jar:2.0.1:compile
[DEBUG] org.apache.maven:maven-model:jar:2.0.1:compile
[DEBUG] org.apache.maven:maven-artifact-manager:jar:2.0.1:compile
[DEBUG] org.apache.maven:maven-repository-metadata:jar:2.0.1:compile
[DEBUG] org.codehaus.plexus:plexus-utils:jar:1.0.5:compile
[DEBUG] classworlds:classworlds:jar:1.1-alpha-2:compile
[DEBUG] org.apache.maven:maven-artifact:jar:2.0.1:compile
[DEBUG] org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9:compile
[DEBUG] junit:junit:jar:3.8.1:compile
[DEBUG] ant:ant-launcher:jar:1.6.5:runtime
[DEBUG] ant:ant:jar:1.6.5:compile
Notice that the group ID of the original dependencies is not org.apache.ant
but just ant
. This will cause Maven to include both ant:ant:1.6.5
and org.apache.ant:ant:1.7.1
. However, custom dependencies will come first on the classpath, so you will be able to use the newer ant version.
Upvotes: 5