I'm currently using maven3 with https://maven.apache.org/plugins/maven-war-plugin/ and http://tomcat.apache.org/maven-plugin-2.0/ with http://mojo.codehaus.org/build-helper-maven-plugin/ to add additional sources next to src/main/java
like src/mock/java
When running mvn tomcat7:run
these additional classes but also the test resources are present.
When bundling the WAR (via mvn package
), these fake-resources are excluded.
That is fine in most cases because the war bundle is what we ship and is beeing deployed on prod server.
Problem 1: BUT: The "fake" classes are still entitled in the WAR build what is not clean for productive WARs.
But there is another usecase: Building a WAR file WITH these additional classes AND resources for deploying on a local dev server via Continuous Integration / Deployment (jenkins) That's seems to be tricky...
Problem 2: The current WAR has the fake classes but not the fake-resources ;/
Question: How to EXclude the fake classes in normal build but how to INCLUDE these sources and also the fake resources in WAR build?
here is what I do:
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>src/mock/resources</directory>
</testResource>
</testResources>
…
… // plugins section
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-resources-after-test</id>
<phase>prepare-package</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/src/main/java-fake</source>
<source>${project.basedir}/src/mock/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
</configuration>
</plugin>
This question is related to: