Alexandr
Alexandr

Reputation: 9505

Maven multi module project error

I'm using the followin folder structure:

SpringMvcExample
               \_ pom.xml (root pom)
               \_ parent
                        \_ pom.xml (parent pom)
               \_ model 
                        \_ src
                        \_ pom.xml (child pom)

Here are files examples:

root.pom:

 <groupId>com.pack</groupId>
    <artifactId>SpringMvcExample</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>SpringMvcExample</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <defaultGoal>package</defaultGoal>
    </build>
    <modules>
        <module>parent</module>
        <module>model</module>
    </modules>

parent pom:

<modelVersion>4.0.0</modelVersion>
    <groupId>com.pack</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>parent</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.pack</groupId>
            <artifactId>model</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

model pom:

<modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.pack</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../parent</relativePath>
    </parent>
    <groupId>com.pack</groupId>
    <artifactId>model</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>model</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

When I try to invoke mvn clean install from the model folder I'm getting the following error:

[ERROR] Failed to execute goal on project model: Could not resolve dependencies for project com.pack:model:jar:1.0-SNAPSHOT: Could not find artifact com.pack:model:jar:1.0-SNAPSOT -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project model: Could not resolve dependencies for project com.pack:model:jar:1.0-SNAPSHOT: Could not find artifact com.pack:model:jar:1.0-SNAPSHOT

What should I do to resolve it?

Updated: Cause not all people have met with the same structure, here is a link to blog that describes it, its advantages and drawbacks. And here is an example that I'm trying to reuse.

Upvotes: 4

Views: 5667

Answers (3)

saurav
saurav

Reputation: 3462

Why your parent pom has dependency on its child module ,please remove it and then try.

Reason : When you build this module it will first try to build the parent which needs the child (model-1.0-SNAPSHOT) jar for successful build (as you have provided dependency on it), till now you your child module is not built so its artifact is not available.

For more reference I would like to suggest you have a look at the How build order is determined by Maven Reactor.

From the Specs :

  • a project dependency on another module in the build
  • a plugin declaration where the plugin is another modules in the build
  • a plugin dependency on another module in the build
  • a build extension declaration on another module in the build
  • the order declared in the element (if no other rule applies)

Upvotes: 1

For starters, your parent POM should generally be what you're calling your "root.pom"; modules should be in directories inside the parent's. Having "parent" and "child" as modules of "root" doesn't make sense, and your root POM says that it is "child"'s parent, but the "child" POM says that "parent" is its parent; perhaps you're not familiar with Maven parent POMs?

I note that in your error message, Maven is looking for a version of 1.0-SNAPSOT, without the H. This suggests that you have some cruft in your local repository from a previous local install run, and I suspect that the tangled dependencies are causing Maven to attempt resolution in a different order than what you're expecting, and it's finding a copy of something in your local repository that refers to the version with the typo.

Upvotes: 0

Markus Kreusch
Markus Kreusch

Reputation: 2121

I think the problem is that you have defined a dependency to com.pack:model in the pom.xml for com.pack:parent which itself is the parent of com.pack:model. When building com.pack:model maven looks into the parent pom of model and finds the dependency to com.pack:model. Because you never have build the project before maven does not find the jar in the repository.

I recommend to remove the dependency to com.pack:model from the parent pom.xml. The parent should not have a dependency to one of it's child projects.

Upvotes: 0

Related Questions