2013-11-14 83 views
0

我有我的多項目Maven項目的一些問題。Maven的多項目問題

的問題如下: 我有一個以下面的方式組織了一個項目:

root 
+-- pom.xml 
! 
+-- module1 
!  +-- pom.xml 
+-- module2 
     +-- pom.xml 

module2取決於module1

Module1打包爲war,它還生成module2依賴於的jar文件。 只要在module2中進行更改,即一切正常,即module1.jar已處於遠程回購,但是在mvn clean release:clean release:prepare release:perform期間兩個模塊都發生更改時出現錯誤,說明在遠程回購中找不到module1.jar。 因此,要解決這個問題我已經加入maven-install-pluginModule1的POM文件是這樣的:

   <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-install-plugin</artifactId> 
        <version>2.5.1</version> 
        <configuration> 
         <file>${project.build.directory}/${project.artifactId}-${project.version}.jar</file> 
         <!-- <packaging>jar</packaging> --> 
        </configuration> 
        <executions> 
         <execution> 
          <id>install</id> 
          <phase>compile</phase> 
          <goals> 
           <goal>install</goal> 
          </goals> 
         </execution> 
        </executions> 

每當我註釋掉<packaging>jar</packaging>它試圖安裝Module1 jar文件到本地回購爲war文件(我猜測,由默認它會從POM文件中拾取包裝)。所以我得到這樣的:

[INFO] [INFO] [jar:jar {execution: creation}] 
[INFO] [INFO] Building jar: ${project.build.directory}/${project.artifactId}-${project.version}.jar 
[INFO] [INFO] [install:install {execution: install}] 
[INFO] [INFO] Installing ${project.build.directory}/${project.artifactId}-${project.version}.jar to <.m2_local_repo>/<proper_path>/${project.version}/${project.artifactId}-${project.version}.war 

但是如果我未評論<packaging>jar</packaging>它抱怨說,我在嘗試設置只讀屬性。

所以這個問題我有,我怎麼能我的構建過程中安裝jar文件到我的本地回購?

更新問題瓦特/的module1module2 POM文件中的某些部分:

module2 POM部分:

<parent> 
    <groupId>...</groupId> 
    <artifactId>...</artifactId> 
    <version>1.01-SNAPSHOT</version> 
</parent> 
<artifactId>module2</artifactId> 
<version>1.08-SNAPSHOT</version> 
<packaging>war</packaging> 

...

<dependency> 
    <groupId>...</groupId> 
    <artifactId>module1</artifactId> 
    <version>4.18-SNAPSHOT</version> 
    <scope>compile</scope> 
</dependency> 

module1 POM:

<parent> 
    <groupId>...</groupId> 
    <artifactId>...</artifactId> 
    <version>1.01-SNAPSHOT</version> 
</parent> 
<artifactId>module1</artifactId> 
<version>4.18-SNAPSHOT</version> 
<packaging>war</packaging> 

我添加安裝插件,以確保module1.4.18.jar將本地安裝,這樣module2.0.18.war將能夠使用module1.4.18.jar

+0

你見識什麼是父POM版本和submododules? – MariuszS

+0

根的POM:1.01快照模塊1:4.18,快照模塊2:1.08的快照和依賴設置是這樣的:\t \t' \t \t \t 模塊1 GRPID \t \t \t 模塊1工件ID \t \t \t 4.18-SNAPSHOT \t \t \t 編譯 \t \t' –

+0

父pom有''定義?是父母和模塊中的不同版本的特殊原因? – MariuszS

回答

0

我認爲你的項目有錯誤的配置(而不是在Maven的方式)。正確的配置看起來像這樣

* parent (root) 
    * module1 (war1) 
    * module2 (war2) 
    * jar (shared code from war2) 

從戰爭將你的代碼單獨的模塊,該模塊depdency添加到這兩個戰爭的模塊。

+0

是真的,但它會嘗試從遠程存儲庫解析它們,在我的情況下''module1.jar'不存在,但 –

+0

否,不應該。從父POM調用'mvn clean install',在本地回購中正確安裝所有子模塊? – MariuszS

+0

當我回答你的問題上面,它試圖安裝jar到本地回購作爲戰爭 –

0

最終我與<goal>install-file</goal>去的<goal>install</goal> 這樣我能夠指定適當的包裝,而不是(事實證明,packaginginstall目標是隻讀的,但是你可以重寫它install-file

所以這是我結束了:

<plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-install-plugin</artifactId> 
     <version>2.5.1</version> 
     <executions> 
      <execution> 
       <id>install</id> 
       <phase>compile</phase> 
       <goals> 
        <goal>install-file</goal> 
       </goals> 
      <configuration> 
       <file>${project.build.directory}/${project.artifactId}-${project.version}.jar</file> 
       <packaging>jar</packaging> 
      </configuration> 
      </execution> 
     </executions> 
    </plugin> 

@MariuszS和@將 - 感謝您對此事

+0

而不是使用'maven-install-plugin',你也可以使用[build-helper:attach-artifact](http://mojo.codehaus.org/ build-helper-maven-plugin/attach-artifact-mojo.html),但通常以這種方式配置項目是一個壞主意。 – MariuszS