Maven - display-dependency-updates- list transitive dependency versions - java

I'd like to be able to see if any of the dependencies of my project - including transitive ones - have updates available.
Take the following 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.me</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
</project>
When I run goal versions:display-dependency-updates I get:
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------------< org.me:test >-----------------------------
[INFO] Building test 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.8.1:display-dependency-updates (default-cli) # test ---
[INFO] No dependencies in Dependencies have newer versions.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.939 s
[INFO] Finished at: 2022-01-12T17:09:39Z
[INFO] ------------------------------------------------------------------------
But when I run dependency:tree, I can now see:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # test ---
[INFO] org.me:test:jar:0.0.1-SNAPSHOT
[INFO] \- org.apache.poi:poi:jar:5.1.0:compile
[INFO] +- commons-codec:commons-codec:jar:1.15:compile
[INFO] +- org.apache.commons:commons-collections4:jar:4.4:compile
[INFO] +- org.apache.commons:commons-math3:jar:3.6.1:compile
[INFO] +- commons-io:commons-io:jar:2.11.0:compile
[INFO] +- com.zaxxer:SparseBitSet:jar:1.2:compile
[INFO] \- org.apache.logging.log4j:log4j-api:jar:2.14.1:compile
And an outdated version of log4j appears.
Is there a way of doing this that's not manual?
I've also tried dependency-updates-report with the processDependencyManagementTransitive option enabled (which is the default) and the transitive dependencies aren't listed.

Related

How can I fix the unexpected clean phase caused by maven 3.3.9's build order and use ${revision}

I have a multi-module maven project, it's a springboot project.
Because of our company's jenkins script, I need to copy the runnable module(with the spring main class) to the root pom menu and I use Maven CI Friendly Versions's placeholder ${revision} to make the version simplify, but it's not work because the build order deleted the .jar file in maven 3.3.9 after copy, and it's works when the maven version is 3.8.2.
I write a demo project to reproduce the problem, the root pom is called demo-root, and a web module called demo-web.
Here's my root pom
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>demo-root</artifactId>
<version>${revision}</version>
<modules>
<module>demo-web</module>
</modules>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.6</version>
</parent>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<revision>1.0-SNAPSHOT</revision>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>demo-web</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.2.2</version>
<configuration>
</configuration>
<executions>
<!-- enable flattening -->
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<!-- ensure proper cleanup -->
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Here's my module pom:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>demo-root</artifactId>
<groupId>org.example</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>demo-web</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<finalName>demo-project</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.example</groupId>
<artifactId>demo-web</artifactId>
<type>jar</type>
<overWrite>true</overWrite>
<destFileName>demo-project.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>../target</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
Then, I run the mvn clean package under the root dir(with the .pom file).
Here's the build log, we can see that the build order is 'demo-web' -> 'demo-root'.
And under the log we can see that build order make the clean after the copy, that deleted the .jar file.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] demo-web
[INFO] demo-root
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building demo-web 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # demo-web ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/demo-web/target
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:clean (flatten.clean) # demo-web ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/demo-web/.flattened-pom.xml
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) # demo-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 0 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:flatten (flatten) # demo-web ---
[INFO] Generating flattened POM of project org.example:demo-web:jar:1.0-SNAPSHOT...
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # demo-web ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/admin/repo#jin/demo-root/demo-web/target/classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) # demo-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory /Users/admin/repo#jin/demo-root/demo-web/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # demo-web ---
[INFO] Changes detected - recompiling the module!
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # demo-web ---
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) # demo-web ---
[INFO] Building jar: /Users/admin/repo#jin/demo-root/demo-web/target/demo-project.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.5.6:repackage (repackage) # demo-web ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --- maven-dependency-plugin:3.1.2:copy (copy) # demo-web ---
[INFO] Configured Artifact: org.example:demo-web:?:jar
[INFO] Copying demo-project.jar to /Users/admin/repo#jin/demo-root/target/demo-project.jar
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building demo-root 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # demo-root ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/target
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:clean (flatten.clean) # demo-root ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/.flattened-pom.xml
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:flatten (flatten) # demo-root ---
[INFO] Generating flattened POM of project org.example:demo-root:pom:1.0-SNAPSHOT...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] demo-web ........................................... SUCCESS [ 4.592 s]
[INFO] demo-root .......................................... SUCCESS [ 0.095 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.940 s
[INFO] Finished at: 2021-10-26T00:44:10+08:00
[INFO] Final Memory: 34M/120M
[INFO] ------------------------------------------------------------------------
If I change the maven version to 3.8.2, and then run the mvn clean package.
it works well.
Here's the build log, and under the log we can see that the build order is 'demo-root' ->
'demo-web', so the copy is after the clean delete, and we can get the .jar file.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] demo-root [pom]
[INFO] demo-web [jar]
[INFO]
[INFO] -----------------------< org.example:demo-root >------------------------
[INFO] Building demo-root 1.0-SNAPSHOT [1/2]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # demo-root ---
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:clean (flatten.clean) # demo-root ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/.flattened-pom.xml
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:flatten (flatten) # demo-root ---
[INFO] Generating flattened POM of project org.example:demo-root:pom:1.0-SNAPSHOT...
[INFO]
[INFO] ------------------------< org.example:demo-web >------------------------
[INFO] Building demo-web 1.0-SNAPSHOT [2/2]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # demo-web ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/demo-web/target
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:clean (flatten.clean) # demo-web ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/demo-web/.flattened-pom.xml
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) # demo-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 0 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:flatten (flatten) # demo-web ---
[INFO] Generating flattened POM of project org.example:demo-web:jar:1.0-SNAPSHOT...
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # demo-web ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/admin/repo#jin/demo-root/demo-web/target/classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) # demo-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory /Users/admin/repo#jin/demo-root/demo-web/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # demo-web ---
[INFO] Changes detected - recompiling the module!
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # demo-web ---
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) # demo-web ---
[INFO] Building jar: /Users/admin/repo#jin/demo-root/demo-web/target/demo-project.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.5.6:repackage (repackage) # demo-web ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --- maven-dependency-plugin:3.1.2:copy (copy) # demo-web ---
[INFO] Configured Artifact: org.example:demo-web:?:jar
[INFO] Copying demo-project.jar to /Users/admin/repo#jin/demo-root/target/demo-project.jar
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for demo-root 1.0-SNAPSHOT:
[INFO]
[INFO] demo-root .......................................... SUCCESS [ 1.366 s]
[INFO] demo-web ........................................... SUCCESS [ 3.800 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.653 s
[INFO] Finished at: 2021-10-26T00:48:13+08:00
[INFO] ------------------------------------------------------------------------
If I replace the ${revision} to '1.0-SNAPSHOT', it works well, and I can get a .jar file under the root's target dir.
Here is the build log:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] demo-root
[INFO] demo-web
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building demo-root 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # demo-root ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/target
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:clean (flatten.clean) # demo-root ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/.flattened-pom.xml
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:flatten (flatten) # demo-root ---
[INFO] Generating flattened POM of project org.example:demo-root:pom:1.0-SNAPSHOT...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building demo-web 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # demo-web ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/demo-web/target
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:clean (flatten.clean) # demo-web ---
[INFO] Deleting /Users/admin/repo#jin/demo-root/demo-web/.flattened-pom.xml
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) # demo-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 0 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- flatten-maven-plugin:1.2.2:flatten (flatten) # demo-web ---
[INFO] Generating flattened POM of project org.example:demo-web:jar:1.0-SNAPSHOT...
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # demo-web ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/admin/repo#jin/demo-root/demo-web/target/classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) # demo-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory /Users/admin/repo#jin/demo-root/demo-web/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # demo-web ---
[INFO] Changes detected - recompiling the module!
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # demo-web ---
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) # demo-web ---
[INFO] Building jar: /Users/admin/repo#jin/demo-root/demo-web/target/demo-project.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.5.6:repackage (repackage) # demo-web ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --- maven-dependency-plugin:3.1.2:copy (copy) # demo-web ---
[INFO] Configured Artifact: org.example:demo-web:?:jar
[INFO] Copying demo-project.jar to /Users/admin/repo#jin/demo-root/target/demo-project.jar
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] demo-root .......................................... SUCCESS [ 1.110 s]
[INFO] demo-web ........................................... SUCCESS [ 3.545 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.562 s
[INFO] Finished at: 2021-10-26T00:51:36+08:00
[INFO] Final Memory: 29M/104M
[INFO] ------------------------------------------------------------------------
So, the problem is happened with 3 pre-condition:
1、use maven-dependency-plugin to copy the module .jar file to the root dir.
2、use the ${revision} placeholder to the version tag.
3、run mvn clean package command in maven 3.3.9
How can I fix this problem when I can't change the maven version(cause the 3.3.9's a company version, change it make a lot of effect). And still want to copy the .jar to the root dir(cause the jenkins script is a company specification). And keep the ${revision} benefit to multi-version control.
If you really cannot change the Maven version, I would no use the ${revision} and instead add the versions directly.
You can then update all versions in a project by calling mvn versions:set -DnewVersion=1.2.3-SNAPSHOT

Why does resolved dependencies differ between Java 8 and Java 11?

Given a very simple Maven project with a single pom-file containing a single dependency:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>maven-test</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.cxf.xjc-utils</groupId>
<artifactId>cxf-xjc-runtime</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies>
</project>
When running mvn dependency:tree different results are given depending on Java version.
With Java 8:
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< org.example:maven-test >-----------------------
[INFO] Building maven-test 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # maven-test ---
[INFO] org.example:maven-test:jar:1.0-SNAPSHOT
[INFO] \- org.apache.cxf.xjc-utils:cxf-xjc-runtime:jar:3.3.0:compile
[INFO] \- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.2:compile
[INFO] \- jakarta.activation:jakarta.activation-api:jar:1.2.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.982 s
[INFO] Finished at: 2020-06-22T15:05:56+02:00
[INFO] ------------------------------------------------------------------------
With Java 11:
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< org.example:maven-test >-----------------------
[INFO] Building maven-test 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # maven-test ---
[INFO] org.example:maven-test:jar:1.0-SNAPSHOT
[INFO] \- org.apache.cxf.xjc-utils:cxf-xjc-runtime:jar:3.3.0:compile
[INFO] +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.2:compile
[INFO] | \- jakarta.activation:jakarta.activation-api:jar:1.2.1:compile
[INFO] +- javax.annotation:javax.annotation-api:jar:1.3.1:compile <-- This and below only with Java 11
[INFO] +- javax.xml.ws:jaxws-api:jar:2.3.0:compile
[INFO] | +- javax.xml.bind:jaxb-api:jar:2.3.0:compile
[INFO] | \- javax.xml.soap:javax.xml.soap-api:jar:1.4.0:compile
[INFO] \- javax.activation:activation:jar:1.1.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.261 s
[INFO] Finished at: 2020-06-22T15:05:51+02:00
[INFO] ------------------------------------------------------------------------
I would have expected the trees to be the same under the two Java versions.
Maven version is 3.6.0.
Why do the resolved dependencies differ between the Java versions?
The reason why the dependency tree differs between the Java versions is found in the dependency:
<dependency>
<groupId>org.apache.cxf.xjc-utils</groupId>
<artifactId>cxf-xjc-runtime</artifactId>
<version>3.3.0</version>
</dependency>
This in turn has xjc-utils as its parent:
<parent>
<groupId>org.apache.cxf.xjc-utils</groupId>
<artifactId>xjc-utils</artifactId>
<version>3.3.0</version>
</parent>
In this POM file, we find the dependencies that are excluded when building with Java 8:
<profile>
<id>java9-plus</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</profile>
This pretty much speacks for itself, the dependencies will only be included if Java 9 or above is used, as stated in this range: <jdk>[9,)</jdk>. The documentation for the tag states:
Specifies that this profile will be activated when a matching JDK is detected. For example, 1.4 only activates on JDKs versioned 1.4, while !1.4 matches any JDK that is not version 1.4.
This activation profile makes sure these dependencies are included when Java 11 is used:
[INFO] +- javax.annotation:javax.annotation-api:jar:1.3.1:compile
[INFO] +- javax.xml.ws:jaxws-api:jar:2.3.0:compile
[INFO] | +- javax.xml.bind:jaxb-api:jar:2.3.0:compile
[INFO] | \- javax.xml.soap:javax.xml.soap-api:jar:1.4.0:compile
[INFO] \- javax.activation:activation:jar:1.1.1:compile
More info about activation can be found in the official Maven documentation:
Activations are the key of a profile. The power of a profile comes from its ability to modify the basic POM only under certain circumstances. Those circumstances are specified via an activation element.
Together with another example of activation based on Java version:
<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
https://maven.apache.org/xsd/maven-4.0.0.xsd">
...
<profiles>
<profile>
<id>test</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.5</jdk>
<os>
<name>Windows XP</name>
<family>Windows</family>
<arch>x86</arch>
<version>5.1.2600</version>
</os>
<property>
<name>sparrow-type</name>
<value>African</value>
</property>
<file>
<exists>${basedir}/file2.properties</exists>
<missing>${basedir}/file1.properties</missing>
</file>
</activation>
...
</profile>
</profiles>
</project>
Dependency tree mojo trims lower level dependencies if the dependency is already present higher in the tree.
We can use verbose flag (-Dverbose) to show the excluded dependencies.
To find a specific artifact : mvn dependency:tree -Dverbose -Dincludes=[groupId]:[artifactId]:[type]:[version]
Please visit Maven Dependency Tree to know more.

Maven is not using dependency version specified in pom.xml

I have a project A, which has B and C dependencies.
The project B also depends on C.
In project A pom, I have:
<dependencyManagement>
<dependency>
<groupId>br.com.mygroup</groupId>
<artifactId>C</artifactId>
<version>2</version>
</dependency>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>br.com.mygroup</groupId>
<artifactId>B</artifactId>
<version>BVERSION</version>
</dependency>
<dependency>
<groupId>br.com.mygroup</groupId>
<artifactId>C</artifactId>
<version>2</version>
</dependency>
<dependencies>
In project B(version BVERSION), I have:
<dependencies>
<dependency>
<groupId>br.com.mygroup</groupId>
<artifactId>C</artifactId>
<version>1</version>
</dependency>
</dependencies>
I have added some methods in C dependency in version 2, but the code doesn't compile when I try to use the new methods. That is, I can't access the new methods. Project A is using version 1(which is inside project B) of C.
If I change the order of the import in project A pom from B, C to C, B, the code compiles, but at execution time a get java.lang.NoSuchMethodError error.
Shouldn't maven dependencyManagement deal with this problem and force project A to use version 2 of C? Does anyone have an idea of what I am getting wrong?
EDIT 1:
mvn dependency:tree returns the following:
[INFO] br.com.mygroup:A:1.0-SNAPSHOT
[INFO] +- br.com.mygroup:B:jar:BVERSION:compile
[INFO] +- br.com.mygroup:C:jar:2:compile
EDIT 2:
mvn dependency:list returns the following:
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< br.com.mygroup:A >---------------------
[INFO] Building A 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:list (default-cli) # A ---
[INFO]
[INFO] The following files have been resolved:
[INFO] br.com.mygroup:B:jar:BVERSION:compile
[INFO] br.com.mygroup:C:jar:2:compile
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.639 s
[INFO] Finished at: 2019-10-04T09:03:37-03:00
[INFO] ------------------------------------------------------------------------

Maven Versions Plugin: versions:use-releases does nothing

I need change all snapshots dependency of my project before pass to release. I'm trying versions:use-releases from commandline mvn versions:use-releases, but it doesn't work for me. I'm using Nexus repository for releases and the releases versions are deployed correcly and with public access
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.efx.util</groupId>
<artifactId>efx-util</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
When I execute: mvn versions:use-releases, it does nothing.
[INFO] ------------------------------------------------------------------------
[INFO] Building efx-clientesocket 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:use-releases (default-cli) # efx-clientesocket ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building efx-clientesocket-api 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:use-releases (default-cli) # efx-clientesocket-api ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building efx-clientesocket-impl 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:use-releases (default-cli) # efx-clientesocket-impl ---
[INFO] Ignoring reactor dependency: com.efx.clientesocket:efx-clientesocket-api:jar:0.0.1-SNAPSHOT
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building efx-clientesocket-conf 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:use-releases (default-cli) # efx-clientesocket-conf ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] efx-clientesocket .................................. SUCCESS [ 1.539 s]
[INFO] efx-clientesocket-api .............................. SUCCESS [ 0.031 s]
[INFO] efx-clientesocket-impl ............................. SUCCESS [ 0.016 s]
[INFO] efx-clientesocket-conf ............................. SUCCESS [ 0.015 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
However versions:display-dependency-updates detect the corresponding release
------------------------------------------------------------------------
[INFO] Building efx-clientesocket-conf 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:display-dependency-updates (default-cli) # efx-clientesocket-conf ---
[INFO] artifact junit:junit: checking for updates from nexus
[INFO] The following dependencies in Dependency Management have newer versions:
[INFO] com.efx.util:efx-util ................ 0.0.1-SNAPSHOT -> 1.0.0-RELEASE
[INFO] junit:junit ............................................. 4.11 -> 4.12
[INFO]
[INFO] ------------------------------------------------------------------------
And I'm also trying versions:use-last-releases as alternative and it goes OK. I'm using -Dincludes= in this case to avoid updating no-snapshot versions. But, I would like to use versions:use-releases to assure updating only all-snapshot versions and cover versions in property at once
Maven version I'm using is 3.3.1 the plugin version is 2.2
Someone have any idea why does not working??
1- versions:use-releases searches the pom for all -SNAPSHOT versions which have been released and replaces them with the corresponding release version.
com.efx.util:efx-util ................ 0.0.1-SNAPSHOT -> 1.0.0-RELEASE
This means efx-util-0.0.1-SNAPSHOT should have a corresponding Release efx-util-0.0.1-RELEASE or efx-util-0.0.1 (a released version of 0.0.1) otherwise it won't work. 1.0.0-RELEASE is not a corresponding release
2- versions:use-latest-releases searches the pom for all non-SNAPSHOT versions which have been a newer release and replaces them with the latest release version.
In this case it's not restricted to the corresponding release of (0.0.1-SNAPSHOT). So the release may have a different version number (1.0.0-RELEASE).
hope this helps.

Maven not running Test [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I created a new maven project in Eclipse that runs simple test by using both HtmlUnitDriver and FirefoxDriver to pull up a web page and check the title on the page. When I run maven command mvn test this is all that I get:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # my-app ---
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/Andrew/Development/code/my-app/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # my-app ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # my-app ---
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/Andrew/Development/code/my-app/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) # my-app ---
[WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/Andrew/Development/code/my-app/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # my-app ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.049s
[INFO] Finished at: Fri Jan 31 11:53:38 EST 2014
[INFO] Final Memory: 12M/81M
[INFO] ------------------------------------------------------------------------
When I run the same Maven command in Eclipse, it shows the following:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # my-app ---
[debug] execute contextualize
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/Andrew/Development/code/my-app/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # my-app ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) # my-app ---
[debug] execute contextualize
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/Andrew/Development/code/my-app/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) # my-app ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) # my-app ---
[INFO] Surefire report directory: /Users/Andrew/Development/code/my-app/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.878s
[INFO] Finished at: Fri Jan 31 11:58:23 EST 2014
[INFO] Final Memory: 5M/81M
[INFO] ------------------------------------------------------------------------
This is my pom.xml for those who want to check if that may be the issue:
<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.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.39.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire</artifactId>
<version>2.16</version>
<type>pom</type>
</dependency>
</dependencies>
</project>
Did you mean to add org.apache.maven.surefire as a POM dependency under <dependencies>?
Most usages of the Surefire plugin are configured under the <pluginManagement> section:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
</plugin>
</plugins>
</pluginManagement>
</build>

Categories

Resources