2012-02-13 71 views
2

我使用build-helper-maven-plugin作爲具有非標準樹文件夾的傳統項目。使用build-helper-maven-plugin和多模塊跳過測試

我使用這種方式:

 <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>build-helper-maven-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>add-source</id> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>add-source</goal> 
        </goals> 
        <configuration> 
         <sources> 
          <source>${basedir}/firstmodule/src</source> 
          <source>${basedir}/secondmodule/src</source> 
         </sources> 
        </configuration> 
       </execution> 
       <execution> 
        <id>add-test-source</id> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>add-test-source</goal> 
        </goals> 
        <configuration> 
         <sources> 
          <source>${basedir}/firstmodule/tests</source> 
          <source>${basedir}/secondmodule/tests</source> 
                 </sources> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

它正常工作,如果我啓動MVN在項目的根目錄安裝,測試通過。

但是,這個項目是一個更大項目中的子模塊。 如果我在父項目的根文件夾中啓動mvn install,maven不會執行測試。

似乎工作萬無一失,但沒有檢測到任何測試:

[INFO] Building MyLegacyProject 
[INFO] task-segment: [clean, install] 
[INFO] ------------------------------------------------------------------------ 
[INFO] [clean:clean {execution: default-clean}] 
[INFO] Deleting directory C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\target 
[INFO] [build-helper:add-source {execution: add-source}] 
[INFO] Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\firstmodule\src added. 
[INFO] Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\secondmodule\src added. 
[INFO] [build-helper:add-test-source {execution: add-test-source}] 
[INFO] Test Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\firstmodule\tests added. 
[INFO] Test Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\secondmodule\tests added. 
[debug] execute contextualize 
[INFO] [resources:resources {execution: default-resources}] 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 40 resources 
[INFO] Copying 40 resources 
[WARNING] While downloading com.sun.xml:saaj-impl:1.3 
    This artifact has been relocated to com.sun.xml.messaging.saaj:saaj-impl:1.3. 


[WARNING] While downloading javax.xml:jaxb-api:2.1 
    This artifact has been relocated to javax.xml.bind:jaxb-api:2.1. 


[INFO] [compiler:compile {execution: default-compile}] 
[INFO] Compiling 752 source files to C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\target\classes 
[debug] execute contextualize 
[INFO] [resources:testResources {execution: default-testResources}] 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 2 resources 
[INFO] Copying 34 resources 
[INFO] [compiler:testCompile {execution: default-testCompile}] 
[INFO] Compiling 15 source files to C:\DEV\perforce\1992\depot\MyLegacyProject\release\BUG_FIXING\MyLegacyProject\target\test-classes 
[INFO] [surefire:test {execution: default-test}] 
[INFO] Surefire report directory: C:\DEV\perforce\1992\depot\MyLegacyProject\release\BUG_FIXING\MyLegacyProject\target\surefire-reports 

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 
Running TestSuite 
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.381 sec 

Results : 

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 

任何想法如何做這項工作?

+0

那麼,15個測試類被編譯。你有自定義的surefire配置嗎? – Raghuram 2012-02-13 10:43:47

+0

不,surefire未配置,我使用默認設置 – 2012-02-13 18:04:40

回答

0

好的我發現它!

有人有同樣的問題: https://stackoverflow.com/a/6925096/242658

但是真的很難理解它

它與build-helper-maven-plugin無關,我不知道爲什麼我在單模塊模式下沒有這個問題。

我使用了TestNG中的powermock和powermock。用testng,我的測試不會被surefire檢測到。所以我不得不排除testng:

<dependency> 
    <groupId>org.powermock</groupId> 
    <artifactId>powermock-mockito-release-full</artifactId> 
    <version>1.4.9</version> 
    <classifier>full</classifier> 
    <exclusions> 
    <exclusion> 
     <artifactId>powermock-module-testng</artifactId> 
     <groupId>org.powermock</groupId> 
    </exclusion> 
    </exclusions> 
</dependency> 
0

嘗試使用調試模式(-X)啓動mvn以查看由surefire使用的屬性是否適用於您的樹文件夾。

0

您使用的是Maven 3嗎? $ {basedir}只被maven 3識別(並默默地被maven 2忽略:() 你是如何理解basedir的用法?它是構建開始的POM的目錄路徑,因此它可能是父項目目錄或其中一個模塊,具體取決於你從哪裏啓動構建,在第二種情況下,路徑將是錯誤的,我想你總是會有項目根目錄的路徑嗎

+0

我正在使用maven2。我已經提交了一些代碼來嘗試用一個簡單的項目進行重現:https://bitbucket.org/hlassiege/maven-build-helper/src然而,它適用於這個示例。我試圖找出與我的「現實生活」項目的不同之處關於basedir,我第一次嘗試沒有它,但我懷疑是路徑問題。所以我天真地嘗試過basedir。 @靈光venisse – 2012-02-14 10:35:24