首页 文章

Maven WAR文件不排除测试类

提问于
浏览
0

我正试图用Maven从我的最终WAR文件中排除测试类 . 通常情况下,如果我的测试在src / test / java中,它应该默认完成,但在我的情况下它没有这样做 . 测试类在WEB-INF \ test-classes \文件夹中编译 . 所以我在pom.xml中添加了以下插件

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

但即便如此,我的测试类仍然包含在最终的.war文件中是否有人有解决方法或者可以解释我缺少的内容?谢谢

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>

1 回答

  • 0

    好吧问题是我使用maven package 目标,其中不包括集成测试 . 跑m vn install 解决了我的问题!谢谢

相关问题