2012-10-04 114 views
0

我有以下項目結構Maven的組裝插件有效:在這種情況下

  1. 工程「父項目」沒有任何的源文件,並具有子項目爲「基於JUnit的包裝」,「child1-測試「和」child2測試「。
  2. 子項目「junit-wrapper」在src/main/java中只有java源代碼,基本上創建它是爲了將所有依賴項和二進制文件包裝在層次結構「parent-project」下。
  3. 子項目「child1-test」和「child2-test」沒有源文件,只包含子項目「child1-env」和「child2-env」。
  4. 子項目「child1-env」和「child2-env」在src/test/java中只有junits。

我想通過建立家長的pom.xml打造超級罐子(基於JUnit的包裝內)

我希望這可以通過使用maven具組件插件,但不知道如何配置此在pom.xml中。爲了確保達到這個目的,應該使用我的pom.xml或assembly.xml(使用插件)條目?

請建議。

感謝。

+0

你喜歡在其他模塊/項目中重用junit-wrapper的分類嗎? – khmarbaise

回答

0

你會得到你的「尤伯杯罐子」當你有這個配置成junit-wrapper的POM文件:

<build> 
    <plugins> 
    <plugin> 
     <artifactId>maven-assembly-plugin</artifactId> 
     <version>2.2.1</version> 
     <executions> 
     <execution> 
      <id>make-assembly</id> 
      <phase>package</phase> 
      <goals> 
      <goal>single</goal> 
      </goals> 
      <configuration> 
      <descriptorRefs> 
       <descriptorRef>jar-with-dependencies</descriptorRef> 
      </descriptorRefs> 
      </configuration> 
     </execution> 
     </executions> 
    </plugin> 
    </plugins> 
</build> 

的組件描述符(assembly.xml)是沒有必要的,因爲jar-with-dependencies描述已經可用在maven-assembly-plugin中。請注意,您不應該在package階段之前執行程序集插件。否則,你的maven模塊的代碼將不會被打包到你的程序集中。

+0

此外,如果您打算將child1-env和child2-env的測試包含在超級jar中,則必須將它們聲明爲依賴項,並且必須確保您正在構建測試代碼中的Jars那兩個包。 –

2

創建一個包含測試類的最佳解決方案是使用maven-JAR-插件這樣的罐子:

<project> 
    <build> 
    <plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-jar-plugin</artifactId> 
     <version>2.2</version> 
     <executions> 
     <execution> 
      <goals> 
      <goal>test-jar</goal> 
      </goals> 
     </execution> 
     </executions> 
    </plugin> 
    </plugins> 
    </build> 
</project> 

在其他模塊,您可以通過以下依賴使用測試-JAR:

<project> 
    ... 
    <dependencies> 
    <dependency> 
     <groupId>com.myco.app</groupId> 
     <artifactId>foo</artifactId> 
     <version>1.0-SNAPSHOT</version> 
     <type>test-jar</type> 
     <scope>test</scope> 
    </dependency> 
    </dependencies> 
    ... 
</project>