2016-06-10 106 views
0

我已經在我的項目主要包含子項目一個子項目乙和當過我做的子項目A和B.子項目Eclipse運行配置 - 在單個配置中運行多個配置?

改變我必須做的行家清潔和Maven安裝子項目的情況A和子項目B ,然後進行主項目更新。

有沒有辦法在單一配置中實現所有這些?

喜歡的東西:

配置MainProject作用: 乾淨,建,清潔,建B,乾淨,打造MainProject。

感謝

回答

1

要做到這一點我在頂層父POM聲明輪廓像這樣

<profile> 
     <id>build-all</id>        
     <modules> 
      <module>MAIN</module>  
      <module>SubProjectA</module>   
      <module>SubProjectB</module>          
     </modules> 
    </profile>  

在Eclipse中運行配置使用父POM路徑作爲基本目錄和「集結所有」作爲簡介。

請記住,您必須將父POM聲明爲其他POMS的父項。

+0

謝謝,請你給我一些參考,我可以在那裏讀到關於超級pom的信息,爲什麼我們需要它。谷歌搜索沒有那麼有用 – Roxy

+0

我應該說「父母POM」,而不是超級POM –

2

有沒有辦法在單一配置中實現所有這些?

當然可以。這是一個Maven多模塊項目的框架:

父POM:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>my.group</groupId> 
    <artifactId>myProject</artifactId> 
    <packaging>pom</packaging> 
    <version>1.0.0-SNAPSHOT</version> 
    <name>myProject</name> 
    <url>http://maven.apache.org</url> 
    <modules> 
     <module>moduleA</module> 
     <module>moduleB</module> 
    </modules> 
    <build> 
      .... 
    </build> 

    <dependencyManagement> 
     <dependencies> 
     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <version>1.2.15</version> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.4</version> 
      <scope>test</scope> 
     </dependency> 
      .... 
     </dependencies> 
    </dependencyManagement> 

    <dependencies> 
      .... 
    </dependencies> 
</project> 

注意的<packaging>pom</packaging>

這是moduleA的POM:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
     <artifactId>myProject</artifactId> 
     <groupId>my.group</groupId> 
     <version>1.0.0-SNAPSHOT</version> 
    </parent> 
    <artifactId>moduleA<artifactId> 
    <name>moduleA</name> 
    <packaging>jar</packaging>  <!-- this is default --> 
    <dependencies> 
     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <!-- no version here, see dependencyManagemant in parent POM --> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <!-- no version here, see dependencyManagemant in parent POM -->    <scope>test</scope> 
     </dependency> 
    </dependencies> 
</project> 

模擬爲moduleB,但依賴性moduleA。現在

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
     <artifactId>nbaWorker</artifactId> 
     <groupId>de.lgn.aaabk</groupId> 
     <version>1.0.0-SNAPSHOT</version> 
    </parent> 
    <artifactId>moduleB</artifactId> 
    <name>moduleB</name> 
    <packaging>jar</packaging>  <!-- this is default --> 

    <dependencies> 
     <dependency> 
      <groupId>my.group</groupId> 
      <artifactId>moduleA</artifactId> 
      <version>1.0.0-SNAPSHOT</version> 
     </dependency> 

     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <!-- no version here, see dependencyManagemant in parent POM --> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <!-- no version here, see dependencyManagemant in parent POM -->    <scope>test</scope> 
     </dependency> 
    </dependencies> 
</project> 

,您可以在父叫mvn clean install只要您撥打一個模塊上的變化。

這裏有更多的信息: Tutorial How do I ...

From Sonatype

From maven Homepage。目前,這不太有用,並且有一個斷開的鏈接。

+0

如果我想在多個父母poms中包含moduleA,該怎麼辦?如何在這種情況下申報? – Roxy

+0

@Roxy嗯......我不知道這是純粹的maven可能。另外我會說在一個以上的多模塊項目中使用模塊違反了這個概念。如果一個模塊在不同的項目中具有普遍的含義,那麼它就是這些項目的依賴。 – JimHawkins

+0

你說得對。這是依賴性,可能我沒有清除我的自我。當我在這些依賴關係中進行一些更改時,我需要首先構建這些依賴項,然後再構建主項目,所以我想要克服構建第一個依賴項的問題。 – Roxy