Reputation: 13
I have several Maven projects which share a common parent as following:
project-parent
project-1
project-2: includes project-1
project-3: includes project-2
Here, project-3
has project-2
in its dependencies and project-2
has project-1
in its dependencies, as an example.
When I push a project to git
, Jenkins
automatically rebuilds to dependent projects. For example, when I push project-3
, project-2
will be rebuilt. Because of that, project-1
will be rebuilt as well. This happens because Jenkins has knowledge about the dependency graph.
However, when I build project-3
locally on my development machine, I have to remember to rebuild project-2
(and project-1
) as well.
I could add a <modules>...</modules>
section to the parent project and simply rebuild the parent project. This will rebuild the whole project, all child projects included. However, I would rather not do that, as there are a lot of projects and some of them require a lot of time to build.
So I want to build one project (the one I'm working on) and somehow automatically (or conveniently) rebuild all dependent projects, similar to the Jenkins behavior. Basically, I want to achieve the Jenkins behavior locally on my development machine. Is this possible?
Upvotes: 1
Views: 713
Reputation: 3138
You can execute the following command from your parent project (assuming you have the my-child-module in the <module>...</module>
:
mvn clean install -pl my-child-module -am
This command will build the project my-child-module
and its dependencies.
-pl, --projects
Build specified reactor projects instead of all projects-am, --also-make
If project list is specified, also build projects required by the list-amd, --also-make-dependents If project list is specified, also build projects that depend on projects on the list
Upvotes: 1
Reputation: 11979
You can also create an aggregator completely independent of the rest: each <module>
point to a path of a folder containing a pom.xml
(it may also directly target a pom.xml).
<project>
...
<modules>
<module>project-parent</module>
<module>project-1</module>
<module>project-2</module>
<module>project-3</module>
</modules>
...
</project>
In this scenario, building from that aggregator will allow maven to take full knowledge of your dependency graph and build in order. You will only have to take care to update properly the version to ensure it match (if project-2 depends of version 2 of project-1 and project-1 is in version 3, then this won't work).
You need not put module you don't want, however be aware that if a module have children <module>
, it will also build them.
Upvotes: 1