tags:

views:

24

answers:

2

I have parent project with:

<modules>
    <module>../module1</module>
    <module>../module2</module>
    <module>../module3</module>
</modules>

and modules with

<parent>
    <groupId>com.cc</groupId>
    <artifactId>parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

Can I somehow specify, that if there are no src at ../module2/ load those module from repository instead fail with Caused by: java.io.FileNotFoundException: C:\work\temp\wid7\workspace\module2 (The system cannot find the file specified.)?

+1  A: 

It's possible to resolve problem via profiles.

<profiles>
    <profile>
        <id>module1</id>
        <activation>
            <file>
                <exists>../module1/pom.xml</exists>
            </file>
        </activation>
        <modules>
            <module>../module1</module>
        </modules>
    </profile>

    <profile>
        <id>module2</id>
        <activation>
            <file>
                <exists>../module2/pom.xml</exists>
            </file>
        </activation>
        <modules>
            <module>../module2</module>
        </modules>
    </profile>
    ...
</profiles>

Profiles concatenate modules block to one. So others modules got from repository.

ArchCC
A: 

While ArchCC has provided an acceptible workaround to your problem, the main issue here is that you are misunderstanding the modules concept.

Modules are build-time relations, not runtime dependencies (although they usually don't make sense unless they are also referenced as dependencies). A multi-module project lets you perform a complex build in one step, using common configuration. Once the build has occured, the <modules> block in the deployed pom has no meaning whatsoever, so it's absolutely pointless to specify modules if you don't have them.

If your issue is that you only want to build part of the project then the solution is to use the advanced reactor commands. Here's an excerpt from mvn --help:

usage: mvn [options] [<goal(s)>] [<phase(s)>]

Options:
 -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
 -pl,--projects <arg>                   Build specified reactor projects
                                        instead of all projects
 -rf,--resume-from <arg>                Resume reactor from specified

Examples:

mvn -am -pl api,client/impl 

build modules api and client/impl (nested modules work here also) with all their dependencies (in the current tree)

mvn -amd -pl core

build module core and all modules that reference it as a dependency

mvn -rf my/deep/nested/module

resume a reactor build from the specified module (scenario: you have a huge build that fails because of a unit test in the 25th module. so you fix the test and continue from where you are, saving the time of re-building all previous modules)


EDIT: I just realize that your modules are outside the root directory. in my opinion, that is a violation of the maven modules concept, because it breaks the reactor functionality specified above.

seanizer
Flat structure of modules not breaks reactor functionality, http://maven.apache.org/plugins/maven-eclipse-plugin/reactor.html Flat Project Layout section. But it's not supported by Release plugin.I am understand ideology of modules, but when you have half hundred modules an need to change only a few, no logic to rebuild all of them, also as no logic to check out it from repository at all.Extended options to reactor help in half of problems, but seem that I try to find too ideal solution =(
ArchCC