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.
source share