簡體   English   中英

如何對多個模塊使用mvn測試?

[英]How do I use mvn test with multiple modules?

我有兩個Maven模塊A和AB,其中AB取決於A中的測試文件。兩者均引用父pom。

我發現了test-jar的魔力,它使我可以編譯程序,但是我仍然無法使用mvn test運行測試。

奇怪的是,mvn軟件包測試似乎有效。

這是我的基本配置:

 ...
 <parent>
   <groupId>com.acme.parent</groupId>
   <artifactId>parent</artifactId>
   <relativePath>../pom.xml</relativePath>
   <version>1.0</version>
 </parent>
 <groupId>com.acme</groupId>
 <artifactId>A</artifactId>     
 <packaging>jar</packaging>
 <version>1.0</version>
 ...

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

項目AB(取決於A)

...
<parent>
  <groupId>com.acme.parent</groupId>
  <artifactId>parent</artifactId>
  <relativePath>../pom.xml</relativePath>
  <version>1.0</version>
</parent>
<artifactId>AB</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<dependency>
  <groupId>com.acme</groupId>
  <artifactId>A</artifact>
  <version>1.0</version>
</dependency>
<dependency>
  <groupId>com.acme</groupId>
  <artifactId>A</artifact>
  <version>1.0</version>
  <type>test-jar</type>
  <scope>test</scope>
</dependency>
...

最后,來自父pom的相關位:

...
<groupId>com.acme.parent</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
  <module>A</module>
  <module>AB</module>
</module>
...

因此,盡管如此,我如何使mvn測試按預期運行?

我正在使用Maven 2.2.1。

這可能與MNG-3559之類的未解決錯誤之一有關。

本質上,如果僅從父pom運行mvn test則Project AB不可見Project A的測試類。 一旦創建了包裝A的罐子(在package階段),它們便可見。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM