After being introduced to Maven in my most recent project, I’ve been experimenting with it for the past couple of weeks.
I currently have a multi-module project in my development environment. Project “A” and Project “B” are child modules of Project “root”, with B having a dependency on A.
I am aware that I can build B independently by using mvn reactor:make... as outlined here. However, I’m curious as to why am I not allowed to build B from inside B’s root folder.
To illustrate this, I first built A independently by running a clean install from within A’s root directory. However, when I tried doing the same action from B’s root directory, Maven reported an error as below –
Could not find artifact org.divesh.mavenrnd:root:pom:1.0 in central
It looks like Maven is not able to resolve the parent’s POM file. Any thoughts on why this is happening? From my initial understanding of Maven multi-module projects, the main reason to split a project into sub modules is to share dependencies. This should not, however, prevent me from building a particular module independently from within its folder.
Thanks.
EDIT
Ran an mvn -N clean install to install only the root project’s POM in the rep. After this, I was able to successfully build B after building and installing A. There is still one thing I’m not quite clear about –
Assuming I’ve installed the root project’s POM in the repository, if I try to build A, does it refer to the parent root POM directly above it or the POM that is installed in the repository?
You should use mvn -pl ProjectToBuild lifecycle like from the root of your tree:
You shouldn’t use mvn reactor:make anymore. Except you are using maven 2.0
If you wan’t to be sure that everything is depending on module-b is build as well you should use:
The best is having a folder layout which represents the appropriate structure of your project and not using relativePath is necessary.