I have a Maven project with multiple modules and sub-modules and i want to compile it at once, i.e. using only one call to "mvn clean install".
For a basic project, the following structure would work:
With the aggregator being:
4.0.0 org.test aggregator pom 1.0.0-SNAPSHOT modules modules/moduleA modules/moduleB
The Super POM:
4.0.0 org.test super-pom pom 1.0.0-SNAPSHOT junit junit 4.11 test
Module A's POM:
4.0.0 moduleA org.test super-pom 1.0.0-SNAPSHOT
Module B is similar.
When at the root of the project, running "mvn clean install" command gives (after cleaning up the .m2/repository folder):
[...] [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] [INFO] super-pom .......................................... SUCCESS [ 0.450 s] [INFO] moduleA ............................................ SUCCESS [ 1.746 s] [INFO] moduleB ............................................ SUCCESS [ 0.029 s] [INFO] agregator .......................................... SUCCESS [ 0.006 s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS
Now if I want something that is more complex (but still using one super POM), such as:
With the root POM being:
4.0.0 org.test agregator pom 1.0.0-SNAPSHOT modules modules/lib1 modules/lib2
Lib1 POM:
4.0.0 org.test lib1-agregator pom 1.0.0-SNAPSHOT moduleA1 moduleB1
And, for instance moduleA1 POM:
4.0.0 moduleA1 org.test super-pom 1.0.0-SNAPSHOT
Maven does not manage to resolve the POM files (after cleaning up the .m2/repository folder):
[INFO] Scanning for projects... [ERROR] [ERROR] Some problems were encountered while processing the POMs: [WARNING] 'parent.relativePath' of POM org.test:moduleA1:[unknown-version] (/Users/ben/IdeaProjects/ComplexMavenStructure/modules/lib1/moduleA1/pom.xml) points at org.test:lib1-agregator instead of org.test:super-pom, please verify your project structure @ line 7, column 13 [FATAL] Non-resolvable parent POM for org.test:moduleA1:[unknown-version]: Could not find artifact org.test:super-pom:pom:1.0.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 7, column 13 [WARNING] 'parent.relativePath' of POM org.test:moduleB1:[unknown-version] (/Users/ben/IdeaProjects/ComplexMavenStructure/modules/lib1/moduleB1/pom.xml) points at org.test:lib1-agregator instead of org.test:super-pom, please verify your project structure @ line 7, column 13 [FATAL] Non-resolvable parent POM for org.test:moduleB1:[unknown-version]: Could not find artifact org.test:super-pom:pom:1.0.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 7, column 13 [WARNING] 'parent.relativePath' of POM org.test:moduleA2:[unknown-version] (/Users/ben/IdeaProjects/ComplexMavenStructure/modules/lib2/moduleA2/pom.xml) points at org.test:lib2-agregator instead of org.test:super-pom, please verify your project structure @ line 7, column 13 [FATAL] Non-resolvable parent POM for org.test:moduleA2:[unknown-version]: Could not find artifact org.test:super-pom:pom:1.0.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 7, column 13 [WARNING] 'parent.relativePath' of POM org.test:moduleB2:[unknown-version] (/Users/ben/IdeaProjects/ComplexMavenStructure/modules/lib2/moduleB2/pom.xml) points at org.test:lib2-agregator instead of org.test:super-pom, please verify your project structure @ line 7, column 13 [FATAL] Non-resolvable parent POM for org.test:moduleB2:[unknown-version]: Could not find artifact org.test:super-pom:pom:1.0.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 7, column 13 @ [ERROR] The build could not read 4 projects -> [Help 1] [ERROR] [ERROR] The project org.test:moduleA1:[unknown-version] (/Users/ben/IdeaProjects/ComplexMavenStructure/modules/lib1/moduleA1/pom.xml) has 1 error [ERROR] Non-resolvable parent POM for org.test:moduleA1:[unknown-version]: Could not find artifact org.test:super-pom:pom:1.0.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 7, column 13 -> [Help 2] [ERROR] [ERROR] The project org.test:moduleB1:[unknown-version] (/Users/ben/IdeaProjects/ComplexMavenStructure/modules/lib1/moduleB1/pom.xml) has 1 error [ERROR] Non-resolvable parent POM for org.test:moduleB1:[unknown-version]: Could not find artifact org.test:super-pom:pom:1.0.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 7, column 13 -> [Help 2] [ERROR] [ERROR] The project org.test:moduleA2:[unknown-version] (/Users/ben/IdeaProjects/ComplexMavenStructure/modules/lib2/moduleA2/pom.xml) has 1 error [ERROR] Non-resolvable parent POM for org.test:moduleA2:[unknown-version]: Could not find artifact org.test:super-pom:pom:1.0.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 7, column 13 -> [Help 2] [ERROR] [ERROR] The project org.test:moduleB2:[unknown-version] (/Users/ben/IdeaProjects/ComplexMavenStructure/modules/lib2/moduleB2/pom.xml) has 1 error [ERROR] Non-resolvable parent POM for org.test:moduleB2:[unknown-version]: Could not find artifact org.test:super-pom:pom:1.0.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 7, column 13 -> [Help 2] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException [ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
I need to first build the super pom:
cd modules/ mvn clean install
And only then will it compile:
[INFO] Reactor Summary: [INFO] [INFO] super-pom .......................................... SUCCESS [ 0.271 s] [INFO] moduleA1 ........................................... SUCCESS [ 1.202 s] [INFO] moduleB1 ........................................... SUCCESS [ 0.027 s] [INFO] lib1-agregator ..................................... SUCCESS [ 0.006 s] [INFO] moduleA2 ........................................... SUCCESS [ 0.027 s] [INFO] moduleB2 ........................................... SUCCESS [ 0.022 s] [INFO] lib2-agregator ..................................... SUCCESS [ 0.007 s] [INFO] agregator .......................................... SUCCESS [ 0.007 s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS
How would you structure the project to make it work without this two-steps compilation?
[EDIT]: as discussed in the comments, adding the relativePath of the Super POM to the modules POMs would make the code compile with one command line.
However, if I want to distribute only lib1 to some developers, even though my super POM is on a Maven repository, lib1 would not compile without the whole project structure. This makes the project less modular.