我有这个项目结构:
/src
/main
/java
/resources
/test
/java
/resources
/it
/java
/resources
test
用于单元测试,it
用于集成测试。我正在使用build-helper-maven-plugin向类路径添加其他测试源/资源,以便以后使用maven-surfire-plugin进行运行
unit tests
的{{1}}和maven-failsafe-plugin。
插件配置如下:
integration tests
这适用于<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>add-integration-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/it/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-integration-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<directory>/src/it/resources</directory>
</resources>
</configuration>
</execution>
</executions>
</plugin>
(它们正确地映射到/ target / test-classes)但不复制 test-resources 。我尝试了test-sources
的不同组合:使用<configuration>
代替<resource>
,使用特定文件而不是目录......但都不起作用。
Stacktrace错误:
<directory>
PROVITHALLY ,我已修复它将集成测试资源添加到maven Caused by: org.apache.maven.plugin.PluginConfigurationException: Unable to parse configuration of mojo org.codehaus.mojo:build-helper-maven-plugin:1.9.1:add-test-resource for parameter directory: Cannot configure instance of org.apache.maven.model.Resource from src/it/resources
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.populatePluginFields(DefaultMavenPluginManager.java:597)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:529)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:92)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
配置:
<build>
但我更愿意在<build>
...
<testResources>
<testResource>
<directory>src/it/resources</directory>
</testResource>
</testResources>
</build>
下集中所有类路径修改。
任何人都可以使用正确的配置发布示例吗?
提前致谢。
答案 0 :(得分:22)
根据maven-build-helper-plugin:add-test-resources的javadoc。 resources
是org.apache.maven.model.Resource
的数组。因此,您必须以这种方式配置它:
<configuration>
<resources>
<resource>
<directory>/src/it/resources</directory>
</resource>
</resources>
</configuration>