I have parent project with:
<modules>
<module>../module1</module>
<module>../module2</module>
<module>../mod开发者_StackOverflowule3</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.)
?
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.
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.
精彩评论