Maven does not recognize child modules when running mvn: tree dependency

I'm trying to set up a multi-module Maven project, and inter-module dependencies seem to be installing incorrectly.

I have:

<modules> <module>commons</module> <module>storage</module> </modules> 

in the parent POM (which has a packing type pom), and then in the commons/ and storage/ subdirectories that define the POM JAR with the same name.

Storage depends on the stock.

In the main (main) directory, I run mvn dependency:tree and see:

 [INFO] Building system [INFO] task-segment: [dependency:tree] [INFO] ------------------------------------------------------------------------ [INFO] [dependency:tree {execution: default-cli}] [INFO] domain:system:pom:1.0-SNAPSHOT [INFO] \- junit:junit:jar:3.8.1:test [INFO] ------------------------------------------------------------------------ [INFO] Building commons [INFO] task-segment: [dependency:tree] [INFO] ------------------------------------------------------------------------ [INFO] [dependency:tree {execution: default-cli}] ...correct tree... [INFO] ------------------------------------------------------------------------ [INFO] Building storage [INFO] task-segment: [dependency:tree] [INFO] ------------------------------------------------------------------------ Downloading: http://my.repo/artifactory/repo/domain/commons/1.0-SNAPSHOT/commons-1.0-SNAPSHOT.jar [INFO] Unable to find resource 'domain:commons:jar:1.0-SNAPSHOT' in repository my.repo (http://my.repo/artifactory/repo) [INFO] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] Failed to resolve artifact. Missing: ---------- 1) domain:commons:jar:1.0-SNAPSHOT 

Why does the dependency on the โ€œcommon commonsโ€ fail, even if the reactor clearly saw it, because it successfully processes its dependency tree? It definitely shouldn't go online to find it like this right there ...

Storage pom:

 <?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <packaging>jar</packaging> <parent> <artifactId>system</artifactId> <groupId>domain</groupId> <version>1.0-SNAPSHOT</version> </parent> <groupId>domain</groupId> <artifactId>storage</artifactId> <name>storage</name> <url>http://maven.apache.org</url> <dependencies> <!-- module dependencies --> <dependency> <groupId>domain</groupId> <artifactId>commons</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <!-- other dependencies --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project> 

Thanks for any suggestions!

(Edit)

To clarify what I'm looking for here is this: I don't want to install module X to build module Y, which depends on X, given that both modules are links from the same parent POM. For me it is intuitively clear that if there are two things in one source tree, I do not need to install intermediate products to continue the assembly. Hope my thinking makes sense here ...

+84
java maven maven-2 dependencies
Nov 04 '09 at 23:47
source share
8 answers

I think the problem is that when you specify the dependency, Maven expects it to be used as a jar (or something else), packaged and available, at least from a local repo. I am sure that if you run mvn install in your commons project, everything will work first.

+20
Nov 05 '09 at 0:10
source share
โ€” -

As discussed in this distribution thread for maven , the goal of the dependency: tree itself will look in the repository, not in the reactor. You can get around this by installing mvn as previously suggested, or by doing something less burdensome that causes the reactor, for example

 mvn compile dependency:tree 

It works for me.

+95
Dec 15 '09 at 8:20
source share

Understanding that this is an older thread, but it seems that either the tool has evolved, or it could have been missed for the first time.

You can perform an assembly that solves problems without installation by assembling the reactor.

If you start a parent assembly that describes the module structure of your project, your dependencies between your modules will be resolved during the assembly itself through the internal Maven reactor.

Of course, this is not an ideal solution, because it does not solve the assembly of a separate separate module within the structure. In this case, Maven will have no dependencies in his reactor, and he will look for a solution in the repository. Therefore, for individual assemblies, you still have to install dependencies first.

Here is a few links describing this situation.

+6
Dec 21 '11 at 2:50
source share

for me, which led me to this topic, there was a similar problem, and the solution was to ensure that every pom module dependency was

  <packaging>pom</packaging> 

the parent had

POM

My dep model had pom - so no jar was found.

+3
Dec 23
source share

The only thing that works for me: switching to gradle :(

I have

 Parent +---dep1 +---war1 (using dep1) 

and I can just cd in war1 and use mvn tomcat7: run-war. I always need to install the entire project earlier, despite the fact that war1 refers to its parent and parent links war1 and dep1 (in the form of modules), so all dependencies should be known.

I do not understand what the problem is.

+3
Nov 12 '15 at 23:05
source share

In the structure of the Maven module:

 - parent - child1 - child2 

You will have in parent pom this:

 <modules> <module>child1</module> <module>child2</module> </modules> 

If you are now dependent on child1 in child2 by adding the following to your <dependencies> in child2 :

 <dependency> <groupId>example</groupId> <artifactId>child1</artifactId> </dependency> 

You will get an error that the JAR for child1 could not be found. This can be solved by declaring a <dependencyManagement> block including child1 in the pom for parent :

 <dependencyManagement> <dependencies> <dependency> <groupId>example</groupId> <artifactId>child1</artifactId> <version>${project.version}</version> </dependency> </dependencies> </dependencyManagement> 

child1 will now be compile when you run the target compile package , etc. for parent , and child2 will find the compiled files child1 .

0
Apr 30 '19 at 5:32
source share

Bonus from the answer from Don Willis :

If your assembly creates test jar files for sharing test code between your reactor submodules, you should use:

 mvn test-compile dependency:tree 

which allows dependency:tree to work to the end in this case.

0
Jul 26 '19 at 19:29
source share

Make sure that the failed module is resolved in pom, and points to the right parent by including configurations in the pom module file.

-one
Jan 11 '17 at 10:39 on
source share



All Articles