Search code examples
mavenwar

Maven WAR file does not exclude test classes


I'm trying to exclude test classes from my final WAR file with Maven. Normally it should be done by default if my tests are in src/test/java but it is not doing it in my case. Test classes are compiled in folder WEB-INF\test-classes\ So I added following plugin in pom.xml

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.2.0</version>
    <configuration>
        <packagingExcludes>**/test-classes/*.class</packagingExcludes>
    </configuration>
 </plugin>

But even with that, my test classes are still included in the .war file at the end Does anyone have a workaround or can explain me what I'm missing ? Thanks

UPDATE : plugins that i use in my pom.xml

         <pluginManagement>
                <plugins>
                    <!-- fix clean issue where duplicated entries of pom are created-->
                    <!--https://bugs.eclipse.org/bugs/show_bug.cgi?id=405915-->
                    <plugin>
                        <artifactId>maven-clean-plugin</artifactId>
                        <version>3.0.0</version>
                        <configuration>
                          <filesets>
                            <fileset>
                              <directory>src/main/webapp/META-INF</directory>
                              <includes>
                                <include>**/pom.properties</include>
                                <include>**/pom.xml</include>
                              </includes>
                            </fileset>
                          </filesets>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>org.eclipse.m2e</groupId>
                        <artifactId>lifecycle-mapping</artifactId>
                        <version>1.0.0</version>
                        <configuration>
                            <lifecycleMappingMetadata>
                                <pluginExecutions>
                                    <pluginExecution>
                                        <pluginExecutionFilter>
                                            <groupId>org.jibx</groupId>
                                            <artifactId>jibx-maven-plugin</artifactId>
                                            <goals>
                                                <goal>bind</goal>
                                            </goals>
                                            <versionRange>[1.2.6,)</versionRange>
                                        </pluginExecutionFilter>
                                        <action>
                                            <execute>
                                                <runOnIncremental>true</runOnIncremental>
                                            </execute>
                                        </action>
                                    </pluginExecution>


                                    <pluginExecution>
                                        <pluginExecutionFilter>
                                            <groupId>org.apache.openjpa</groupId>
                                            <artifactId>openjpa-maven-plugin</artifactId>
                                            <goals>
                                                <goal>enhance</goal>
                                            </goals>
                                            <versionRange>[2.2.2,)</versionRange>
                                        </pluginExecutionFilter>
                                        <action>
                                            <execute>
                                                <runOnIncremental>true</runOnIncremental>
                                            </execute>
                                        </action>
                                    </pluginExecution>

                                    <pluginExecution>
                                        <pluginExecutionFilter>
                                            <groupId>org.apache.maven.plugins</groupId>
                                            <artifactId>maven-antrun-plugin</artifactId>
                                            <goals>
                                                <goal>run</goal>
                                            </goals>
                                            <versionRange>[1.8,)</versionRange>
                                        </pluginExecutionFilter>
                                        <action>
                                            <execute>
                                                <runOnIncremental>false</runOnIncremental>
                                            </execute>
                                        </action>
                                    </pluginExecution>
                                </pluginExecutions>
                                </lifecycleMappingMetadata>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>

            <plugins>  

                <!-- toolchain plugin to use specific JDK 
                 <plugins>
                      <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-toolchains-plugin</artifactId>
                        <version>1.1</version>
                        <executions>
                          <execution>
                            <goals>
                              <goal>toolchain</goal>
                            </goals>
                          </execution>
                        </executions>
                        <configuration>
                          <toolchains>
                            <jdk>
                              <version>1.8</version>
                              <vendor>ibm</vendor>
                            </jdk>
                          </toolchains>
                        </configuration>
                      </plugin>
                    </plugins>
        -->

                  <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.6.1</version>
                    <configuration>
                      <source>1.6</source>
                      <target>1.6</target>
                  <!--     <forceJavacCompilerUse>true</forceJavacCompilerUse>-->
                    </configuration>
                  </plugin>


                <!-- OPENJPA -->
                <plugin>
                    <groupId>org.apache.openjpa</groupId>
                    <artifactId>openjpa-maven-plugin</artifactId>
                    <version>2.2.2</version>
                    <configuration>
                        <includes>com/dsv/express/persistence/domain/*.class</includes>
                        <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
                        <persistenceXmlFile>${project.basedir}${persistenceXmlFile-Path}</persistenceXmlFile>
                    </configuration>
                    <executions>
                        <execution>
                            <id>enhancer</id>
                            <phase>process-classes</phase>
                            <goals>
                                <goal>enhance</goal>
                            </goals>
                        </execution>
                    </executions>
                    <dependencies>
                        <dependency>
                            <groupId>org.apache.openjpa</groupId>
                            <artifactId>openjpa</artifactId>
                            <version>2.2.2</version>
                        </dependency>
                    </dependencies>
                </plugin>


        </plugins>

Solution

  • Well problem was I used maven package goal which did not include integration test. Running mvn install solved my problem ! Thanks