Build single module from multimodule pom

Tag: maven Author: jiayu6465 Date: 2009-10-07

Is it possible to do?

The environment: Multimodule pom consists of 3 modules: mm1, mm2, mm3. Module mm2 has mm1 as dependency. It is possible to build parent pom without any errors.

The question: Is it possible to build single module mm2 (i.e., run maven from mm2 base directory) without installing mm1 into local repository?

Thanks.

Are you Rodolphe? Do you have Free? :D
Sorry, what? :)

Best Answer

Without automatic installing not, but it's possible to build only choosen projects. You need to have multi module build (I'm assuming you do). In reactor mode every command need to be run from the root of reactor.

So in your case:

mvn reactor:make -Dmake.folders=mm2

In this case you build mm2 module and modules on which it depends (mm1).

Useful links:

From book examples I build only project persist and his dependency project model. Others projects are untouched with mvn reactor:make -Dmake.folders=sample-persist

alt text

Other useful command is reactor:make-dependents which build projects that depend on X.

Other Answer1

I'm not sure what you mean exactly by "without installing mm1 into local repository". Do you mean previously to building mm2 or never?

In doubt, maybe one of the new build options announced in the Maven Tips and Tricks: Advanced Reactor Options blog post can help:

Starting with the Maven 2.1 release, there are new Maven command line options which allow you to manipulate the way that Maven will build multimodule projects. These new options are:

-rf, --resume-from
        Resume reactor from specified project
-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

I was specifically thinking to the -pl and -am options. To build a subset of the modules, run the following from the root directory

$ mvn --projects mm2 --also-make install

However, I'm not sure this answers your question (which is not totally clear for me).

comments:

+1 Now I see that I didn't read your post carefully and write nearly the same answer.

Other Answer2

This goes against the principle of dependencies of Maven2. What is the interest of doing that exactly?

However, we can imagine to define the mm1 dependency of mm2 as a system dependency:

<dependency>
    <groupId>...</groupId>
    <artifactId>mm1</artifactId>
    <version>...</version>
    <scope>system</scope>
    <systemPath>../mm1/target/</systemPath>
</dependency>

comments:

This makes my eyes bleeding :)