Maven project error with multiple modules

I use the followin folder structure:

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

Here are sample files:

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> 

pom model:

 <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 call mvn clean install from the model folder, I get 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 to do to allow it?

Updated: Because not all people meet the same structure, here is a link to a blog that describes it, its advantages and disadvantages. And here is an example that I am trying to reuse.

+4
source share
3 answers

Why does your parent pom depend on its child module, remove it, and then try.

Reason:. When you create this module, first try to create a parent element that needs a child jar (model-1.0-SNAPSHOT) for successful assembly (since you provided dependency on it), your child module is still not built, so its artifact is not available.

For more information, I would suggest that you take a look at How assembly order is determined by Maven Reactor .

From the specifications:

  • project dependency on another module in the assembly
  • plugin declaration, where the plugin is another module in the assembly
  • plugin dependency on another module in the assembly
  • declaring an assembly extension on another module in the assembly
  • the order declared in the element (unless another rule applies)
+1
source

I think the problem is that you defined the com.pack: model dependency in pom.xml for com.pack: parent, which itself is the parent of com.pack: model. When creating com.pack: model maven looks at the parent pom of the model and finds a dependency on com.pack: model. Since you never had a project before maven doesn't find the jar in the repository.

I recommend removing the dependency on com.pack: model from the parent pom.xml. A parent must not be dependent on one of his child projects.

0
source

First, your parent POM should usually be what you call your "root.pom"; modules must be in directories inside the parent element. Having a โ€œparentโ€ and โ€œchildโ€ as โ€œrootโ€ modules does not make sense, and your root POM says that it is a โ€œchildโ€ parent, but a โ€œchildโ€ POM says that โ€œparentโ€ is its parent; maybe you are not familiar with parent Pven Maven?

I note that in your error message, Maven is looking for version 1.0-SNAPSOT without H. This suggests that you have some jerk in your local repository from a previous local installation run, and I suspect that the messy dependencies force Maven to execute permission in a different order than what you expect, and find a copy of something in your local repository that references the typo version.

0
source

Source: https://habr.com/ru/post/1496783/


All Articles