Issue
I've got a pretty complex project (about 100 modules) on which I'd like to run mvn dependency:tree
. It fails, complaining about dependencies it cannot resolve. The project otherwise compiles fine. So I created the most basic project I could come up and it still fails with the same error. Obviously either I must be doing some very basic mistake or the maven-dependency-plugin has not been used by anyone yet. Here are the three POMs im by test project:
pom.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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>com.example</groupId>
<artifactId>root</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>foo</module>
<module>bar</module>
</modules>
</project>
foo/pom.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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>com.example</groupId>
<artifactId>foo</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
</project>
bar/pom.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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>com.example</groupId>
<artifactId>bar</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>foo</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Then I issue the following command mvn dependency:tree
in the top-level directory and get the following output:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] foo
[INFO] bar
[INFO] root
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building foo 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ foo ---
[INFO] com.example:foo:jar:1.0.0-SNAPSHOT
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building bar 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] foo ................................................ SUCCESS [ 0.756 s]
[INFO] bar ................................................ FAILURE [ 0.011 s]
[INFO] root ............................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.065 s
[INFO] Finished at: 2015-03-03T16:19:18+01:00
[INFO] Final Memory: 13M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project bar: Could not resolve dependencies for project com.example:bar:jar:1.0.0-SNAPSHOT: Could not find artifact com.example:foo:jar:1.0.0-SNAPSHOT -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :bar
What am I missing? Shouldn't this just work?
Solution
I'm frustrated why it didn't work.
A simple dependency analysis just didn't work.
And the official has no any guide how to do it.
Another much usefully command didn't work neither
mvn dependency:resolve
but, maybe you could try these commands instead
mvn test-compile dependency:resolve
mvn test-compile dependency:tree
anyway, it works for me
Update on Mar 13 2017
We can make it much more faster by skipping the compilation
mvn test-compile dependency:resolve -Dmaven.main.skip=true -Dmaven.test.skip=true
mvn test-compile dependency:tree -Dmaven.main.skip=true -Dmaven.test.skip=true
So sad it didn't work for our project because our project was using kotlin, maybe it is kotlin's bug which didn't skip the compilation, maybe I should report this bug to jetbrains.
Answered By - William Leung
Answer Checked By - Mary Flores (JavaFixing Volunteer)