2010-08-16 60 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