如何爲pom.xml中包含的依賴項提取tests.jars,而不明確指定測試作用域對工件的依賴性。 例如:我的pom.xml包含'n'依賴項,其中大部分還包含tests.jar。當我使用這個pom運行mvn:test時,我想抓住這些依賴性測試並運行它們(因爲父pom是聚合器,並且想要運行測試以確保集成不會破壞事物)。 如果我在這些'n'依賴關係的測試工件中包含依賴項,並使用maven-surefire-plugin和dependenciesToScan組合(如下所示),我可以運行測試。 但是這需要我每次爲依賴關係構建測試jar或添加新的依賴關係時編輯pom.xml。maven自動拉取依賴關係測試jar
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<dependenciesToScan>
<dependency>group:artifact1</dependency>
<dependency>group:artifact2</dependency>
</dependenciesToScan>
</configuration>
</plugin>
..
..
<dependencies>
<dependency>
<groupId>group</groupId>
<artifactId>artifact1</artifactId>
<version>version</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>group</groupId>
<artifactId>artifact2</artifactId>
<version>version</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
....
...
</dependencies>
沒有對測試工件添加明確depenency,是可以自動拉動和運行依賴的測試以及(當然不是全部依賴但一些符合特定組的ID)?
上次編輯沒有改進結果。粘貼XML,選擇它,然後使用編輯器上方的小「代碼」按鈕將其變爲代碼。 –
現在希望它更好。 –
我轉移到gradle上來實現這一點。這是一個使用ant JUnit的簡單任務配置。 http://stackoverflow.com/questions/21439082/gradle-to-run-tests-from-test-dependency-jars有詳細信息。 –