I can't seem to get Maven to find a sibling's module in a multi-module project.
I've run mvn clean install
in all modules.
Here's the setup:
Product
+-- MagniCompCommon
+-- Model
The Model
project has MagniCompCommon
as a dependency. When I run mvn clean compile
in Model
, I get:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Model 1.0
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.magnicomp:MagniCompCommon:jar:1.0 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.585 s
[INFO] Finished at: 2015-10-14T10:09:04-07:00
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project Model: Could not resolve dependencies for project com.magnicomp:Model:jar:1.0: Failure to find com.magnicomp:MagniCompCommon:jar:1.0 in http://download.java.net/maven/2/ was cached in the local repository, resolution will not be reattempted until the update interval of Java.Net has elapsed or updates are forced -> [Help 1]
As you can see, Maven is trying to find MagniCompCommon
in the java.net repo (this is the first repository entry in the parent (Product
) pom.xml
).
Here is Product pom.xml
:
<?xml version="1.0"?>
<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>
<groupId>com.magnicomp</groupId>
<artifactId>Product</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>MagniCompCommon</module>
<module>Model</module>
<module>Common</module>
<module>Agent</module>
<module>Doc</module>
</modules>
... snip ...
<repositories>
<repository>
<id>Java.Net</id>
<url>http://download.java.net/maven/2/</url>
</repository>
Here is MagniCompCommon pom.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>
<parent>
<groupId>com.magnicomp</groupId>
<artifactId>Product</artifactId>
<version>1.0</version>
</parent>
<!-- <groupId>com.magnicomp.common</groupId> -->
<artifactId>MagniCompCommon</artifactId>
<packaging>jar</packaging>
Here is Model 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.magnicomp</groupId>
<artifactId>Product</artifactId>
<version>1.0</version>
</parent>
<artifactId>Model</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.magnicomp</groupId>
<artifactId>MagniCompCommon</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
When you are building a multi-module Maven project, you need to run Maven commands from the root POM. This means you need to run mvn clean install
on Product
's pom.xml
.
The error you are getting is expected: you are only building Model
. In Model
's POM, Maven sees that there is a dependency on MagniCompCommon
so it tries to look for that dependency. First, it searches in your local repo: it fails to find it there since you did not install MagniCompCommon
before. As a result, it looks for it in the predefined remote repositories (and also fails to find it).
You would be able to circumvent this by first running mvn clean install
on MagniCompCommon
's POM, then on Model
POM but this is much easier done by invoking Maven directly on the root POM. It will correctly build every modules in the right order (since Model
depends on MagniCompCommon
, it will build MagniCompCommon
first, then Model
).
As a side note, you can remove the line <packaging>jar</packaging>
because this is the default.