You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Seckin Onur SELAMET (JIRA)" <ji...@apache.org> on 2018/06/05 11:52:00 UTC
[jira] [Commented] (MDEP-609) Dependency analyzer gets confused if
the same package is defined in 2 different artifacts
[ https://issues.apache.org/jira/browse/MDEP-609?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16501643#comment-16501643 ]
Seckin Onur SELAMET commented on MDEP-609:
------------------------------------------
* This issue can be related with MNG-6415 under some conditions but with this simple example it is not the case.
* The reported behavior still observable. It is related with how classpath constructed. _*Dependency plugin is not the root cause.*_
I used a modified pom file for project 2 to have one more level ( for more visible distance) in the dependency tree.
{code:xml}
<?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>test</groupId>
<artifactId>project2</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
</dependency>
</dependencies>
</project>{code}
TREE
{noformat}
[INFO] --- maven-dependency-plugin:3.1.0:tree (default-cli) @ project1 ---
[INFO] test:project1:jar:1.0.0-SNAPSHOT
[INFO] +- test:project2:jar:1.0.0-SNAPSHOT:compile
[INFO] | \- org.mockito:mockito-core:jar:1.9.5:compile
[INFO] | +- org.hamcrest:hamcrest-core:jar:1.1:compile
[INFO] | \- org.objenesis:objenesis:jar:1.0:compile
[INFO] \- org.hamcrest:hamcrest-all:jar:1.1:compile
{noformat}
ANALYZE
{noformat}
[INFO] --- maven-dependency-plugin:3.1.0:analyze (default-cli) @ project1 ---
[WARNING] Used undeclared dependencies found:
[WARNING] org.hamcrest:hamcrest-core:jar:1.1:compile
[WARNING] Unused declared dependencies found:
[WARNING] test:project2:jar:1.0.0-SNAPSHOT:compile
[WARNING] org.hamcrest:hamcrest-all:jar:1.1:compile
{noformat}
CLASSPATH (took the testCompile classpath on purpose to see it was affected by MNG-6415 or not)
{noformat}
[DEBUG] Classpath:
[DEBUG] C:\dev\dummy\P1\target\test-classes
[DEBUG] C:\dev\dummy\P1\target\classes
[DEBUG] C:\dev\Java\maven_repo\test\project2\1.0.0-SNAPSHOT\project2-1.0.0-SNAPSHOT.jar
[DEBUG] C:\dev\Java\maven_repo\org\mockito\mockito-core\1.9.5\mockito-core-1.9.5.jar
[DEBUG] C:\dev\Java\maven_repo\org\hamcrest\hamcrest-core\1.1\hamcrest-core-1.1.jar
[DEBUG] C:\dev\Java\maven_repo\org\objenesis\objenesis\1.0\objenesis-1.0.jar
[DEBUG] C:\dev\Java\maven_repo\org\hamcrest\hamcrest-all\1.1\hamcrest-all-1.1.jar
{noformat}
Under this conditions dependency plugin is just reporting it correctly. :)
The implementation for IsEqual class is provided by hamcrest-core-1.1.jar because hamcrest-core-1.1.jar is the earliest entry in the classpath that has IsEqual class.
> Dependency analyzer gets confused if the same package is defined in 2 different artifacts
> -----------------------------------------------------------------------------------------
>
> Key: MDEP-609
> URL: https://issues.apache.org/jira/browse/MDEP-609
> Project: Maven Dependency Plugin
> Issue Type: Bug
> Components: analyze
> Affects Versions: 3.1.0
> Reporter: Ahmed Hammad
> Priority: Major
>
> The issue might be related to MNG-6415
> If a certain package is defined in 2 different artifacts, and a a maven module declares a dependency on these 2 artifacts (once through a transitive dependency and once using a declared dependency), dependency analyzer reports the dependency as "Used Undeclared", while declared dependencies should always take precedence (even if they appear later in the POM)
> For example:
> Project 1 pom:
> {code:java}
> <?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>test</groupId>
> <artifactId>project1</artifactId>
> <version>1.0.0-SNAPSHOT</version>
> <dependencies>
> <dependency>
> <groupId>test</groupId>
> <artifactId>project2</artifactId>
> <version>1.0.0-SNAPSHOT</version>
> </dependency>
> <dependency>
> <groupId>org.hamcrest</groupId>
> <artifactId>hamcrest-all</artifactId>
> <version>1.1</version>
> </dependency>
> </dependencies>
> </project>
> {code}
> Project 2 pom:
> {code:java}
> <?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>test</groupId>
> <artifactId>project2</artifactId>
> <version>1.0.0-SNAPSHOT</version>
> <dependencies>
> <dependency>
> <groupId>org.hamcrest</groupId>
> <artifactId>hamcrest-core</artifactId>
> <version>1.3</version>
> </dependency>
> </dependencies>
> </project>
> {code}
> And Project 1 uses a package which can be found in both hamcrest-core and hamcrest-all:
> {code:java}
> import org.hamcrest.core.IsEqual;
> class Test {
> IsEqual isEqual;
> }
> {code}
> When doing a dependency analysis for Project 1, no "Used undeclared" are expected to be seen, because Project 1 declares a dependency on hamcrest-all.
> However, I get:
> [INFO] — maven-dependency-plugin:2.8:analyze (default-cli) @ project1 —
> [WARNING] Used undeclared dependencies found:
> [WARNING] org.hamcrest:hamcrest-core:jar:1.3:compile
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)