Usually generated sources should be created in the target dir. But how do I handle classes that are only used for test? I dont want that these classes get packaged in my jar. Is there a common way to deal with this situation?
The “maven-source” plugin is used to pack your source code and deploy along with your project. This is extremely useful, for developers who use your deployed project and also want to attach your source code for debugging.
Maven is the latest build testing tool. It has several new features as compare to Ant, like dependency, etc. Maven is a project build or project management tool. It is used to check the compilation issues between framework components whenever multiple test engineer integrates their files into the same framework.
If we use the default configuration, the Maven Surefire plugin runs all test methods found from the test classes that fulfill these two conditions: The test classes must be found from the src/test/java directory. The name of the test class must start or end with the string: Test.
Configuring the Maven Surefire Plugin We can run our unit tests by using the Maven Surefire Plugin. Because we want to use its native JUnit 5 support, we have to use the version 2.22. 0 (or newer).
Use maven build helper plugin's add-test-source
goal to add your generated test source files to the build -> http://mojo.codehaus.org/build-helper-maven-plugin/add-test-source-mojo.html
It ensures that the directories added by this goal will be picked up automatically by the compiler plugin during test-compile
phase of the build.
EDIT
Here is the example of how to generate code for testign with 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With