[英]Maven: How to handle generated sources for test(only)?
通常應在目標目錄中創建生成的源。 但是我該如何處理僅用於測試的類? 我不希望這些類在我的jar中打包。 有沒有一種常見的方法來處理這種情況?
使用maven build helper插件的add-test-source
目標將生成的測試源文件添加到構建中 - > http://mojo.codehaus.org/build-helper-maven-plugin/add-test-source-mojo.html
它確保在構建的test-compile
階段,編譯器插件將自動拾取由此目標添加的目錄。
編輯
以下是如何使用cxf-codegen-plugin為testign生成代碼的示例
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.