2014-11-05 102 views
1

使用scalatest時遇到了一個奇怪的問題。我有一個包含多個模塊的maven項目。如果我直接在模塊中執行mvn test。它工作沒有問題,但如果我在根文件夾中執行它,它抱怨在編譯時丟失包(依賴項)。Maven模塊無法使用scalatest查找依賴關係

我的配置看起來像如下:

<dependency> 
     <groupId>org.scalatest</groupId> 
     <artifactId>scalatest_${scala.shortversion}</artifactId> 
     <version>3.0.0-SNAP2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.scalatest</groupId> 
     <artifactId>scalatest-maven-plugin</artifactId> 
     <version>1.0</version> 
    </dependency> 

插件配置:

  <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.7</version> 
      <configuration> 
       <skipTests>true</skipTests> 
      </configuration> 
      </plugin> 
      <plugin> 
      <groupId>org.scalatest</groupId> 
      <artifactId>scalatest-maven-plugin</artifactId> 
      <version>1.0</version> 
      <configuration> 
       <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory> 
       <junitxml>.</junitxml> 
       <filereports>WDF TestSuite.txt</filereports> 
      </configuration> 
      <executions> 
       <execution> 
       <id>scala-test</id> 
       <goals> 
        <goal>test</goal> 
       </goals> 
       </execution> 
      </executions> 
      </plugin> 

如果我從maven-scala-plugingoals刪除它會編譯,但scalatest將找不到測試源和退出與No tests were executed.

 <plugin> 
      <version>2.15.2</version> 
      <groupId>org.scala-tools</groupId> 
      <artifactId>maven-scala-plugin</artifactId> 
      <executions> 
       <execution> 
       <goals> 
        <goal>compile</goal> 
        <goal>testCompile</goal> 
       </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <scalaVersion>${scala.version}</scalaVersion> 
      </configuration> 
     </plugin> 

關於我做錯什麼的想法?

乾杯

回答

0

硬盤,沒有看到你所有的勁歌,但一般來講說: 定義根嘭所有依賴於dependencyManagement部分,你與他們的配置pluginManagement部分插件。在孩子poms中只定義你需要的插件和依賴。

請記住,xxx管理部分只建立共享定義,根配置的種類。您仍然必須在插件中定義依賴關係部分您需要但您可以省略版本和配置元素。

這將允許您所有的孩子poms在所有模塊中運行測試。

+0

我繼承了這個項目,不得不清理很多東西。當我重組根目錄中的'pluginManagement'時,我的問題得到了解決。感謝提示! – zio 2014-11-06 14:03:36