2010-08-16 57 views
2

Maven的模块,我有一个父项目:获得从仓库而不是相对文件路径

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

和模块与

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

我可以以某种方式指定,如果有在没有SRC ../module2 /从存储库加载这些模块,而不是以Caused by: java.io.FileNotFoundException: C:\work\temp\wid7\workspace\module2 (The system cannot find the file specified.)失败?

回答

3

可以通过配置文件解决问题。

<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> 

配置文件将模块连接成一个块。所以其他模块从存储库中获取。

+1

这里存储库的用法在哪里? – 2015-04-14 23:29:54

3

虽然ArchCC为您的问题提供了an acceptible workaround,但这里的主要问题是您误解了模块概念。

模块是构建时关系,而不是运行时依赖关系(尽管它们通常没有意义,除非它们也被称为依赖关系)。多模块项目可让您使用常见配置一步完成复杂构建。一旦构建发生,部署pom中的<modules>块没有任何意义,因此如果没有它们,指定模块就毫无意义。

如果您的问题是您只想构建项目的一部分,那么解决方案是使用高级反应堆命令。下面是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 

例子:

mvn -am -pl api,client/impl 

构建模块API和客户端/ IMPL(嵌套模块也在这里工作)及其所有的依赖关系(在当前树)

mvn -amd -pl core 

构建模块核心以及将其作为依赖关系引用它的所有模块

mvn -rf my/deep/nested/module 

从指定模块恢复反应堆构建(场景:由于第25个模块中的单元测试,您的构建失败。所以您修复试验,从你在哪里继续,节省重新建立以前的所有模块的时间)


编辑:我只是意识到你的模块的根目录之外。在我看来,这违反了maven模块的概念,因为它打破了上面指定的反应堆功能。

+0

模块的平面结构不会中断反应堆功能,http://maven.apache.org/plugins/maven-eclipse-plugin/reactor.html平面项目布局部分。但它不受Release插件的支持。 我明白模块的意识形态,但是当你有五百个模块需要改变几个模块,没有逻辑来重建所有模块,也没有逻辑从存储库检出它。 反应堆扩展选项有助于解决一半问题,但似乎我试图找到理想的解决方案=( – ArchCC 2010-08-20 19:56:18