【发布时间】:2013-08-30 20:05:33
【问题描述】:
通常生成的源应该在目标目录中创建。但是如何处理仅用于测试的类?我不希望这些类被打包在我的 jar 中。有没有一种通用的方法来处理这种情况?
【问题讨论】:
通常生成的源应该在目标目录中创建。但是如何处理仅用于测试的类?我不希望这些类被打包在我的 jar 中。有没有一种通用的方法来处理这种情况?
【问题讨论】:
使用 maven build helper 插件的 add-test-source 目标将您生成的测试源文件添加到 build -> http://mojo.codehaus.org/build-helper-maven-plugin/add-test-source-mojo.html
它确保此目标添加的目录将在构建的test-compile 阶段被编译器插件自动拾取。
编辑
这里是如何使用 cxf-codegen-plugin 生成测试代码的示例
<build>
<plugins>
...
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-test-sources</id>
<phase>generate-test-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/wsdl/myService.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>add-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated/cxf</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
【讨论】:
cxf-codegen-plugin添加到generate-test-sources阶段,然后添加build-helper-maven-plugin:add-test-source,编译后的类将仅可用于测试执行