Maven 跳过测试,

Maven skips tests,

我有 Java 8 个 maven 项目,其中有一对模块,每个模块都有自己的 pom.xml,主项目文件夹中有一个 pom.xml。问题是 mvn test 跳过了测试。我 运行 mvn test -Xmaven-surefire-plugin:3.0.0-M3:test 标签下为我提供了

[DEBUG]   (s) skip = true
[DEBUG]   (s) skipTests = true

在我添加的其他 stackoveflow 帖子的帮助下

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
     <skipTests>false</skipTests>
     <skip>false</skip>
  </configuration>
</plugin>

解决了该标签下的问题,但在 maven-compiler-plugin:3.8.0:testCompile 部分下仍然存在:

[DEBUG]   (f) skip = true

测试仍然没有执行,我找不到任何有用的东西。下面是子模块之一的 pom.xml 和主模块 pom.xml,我省略了包括内部依赖项。

main pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>pl.com.REDACTED</groupId>
        <artifactId>bom</artifactId>
        <version>5.6.0</version>
    </parent>

    <artifactId></artifactId>
    <packaging>pom</packaging>
    <version>1.0</version>



    <properties>

     

        <!-- Logging -->
        <log4j.version>1.2.17</log4j.version>
        <slf4j-log4j12.version>1.7.12</slf4j-log4j12.version>
        <guava.version>18.0</guava.version>

        <!-- Arquillian -->
        <arquillian.version>1.1.12.Final</arquillian.version>
        <arquillian_persistence.version>1.0.0.Alpha7</arquillian_persistence.version>
        <arq.version-glassfish-remote>1.0.0.Final</arq.version-glassfish-remote>
        <shrinkwrap-resolver-depchain.version>2.2.5</shrinkwrap-resolver-depchain.version>

        <!-- Lombok -->
        <lombok-maven.version>1.16.16.0</lombok-maven.version>
        <lombok.version>1.18.16</lombok.version>

        <!-- Jackson -->
        <jackson.version>2.25.1</jackson.version>

        <poi.version>3.16</poi.version>
        <maven-failsafe-plugin.version>2.22.1</maven-failsafe-plugin.version>
        <TransferManager-Internal-Common.version>1.1.0-SNAPSHOT</TransferManager-Internal-Common.version>
        <gson.version>2.8.6</gson.version>
    </properties>

    <build>
        <finalName>REDACTED</finalName>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>${maven-failsafe-plugin.version}</version>
                </plugin>

                <plugin>
                    <groupId>org.projectlombok</groupId>
                    <artifactId>lombok-maven</artifactId>
                    <version>${lombok-maven.version}</version>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <skip>false</skip>
                        <skipTests>false</skipTests>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

        <resources>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/resources</directory>
            </resource>
        </resources>

    </build>

    <dependencyManagement>
        <dependencies>
     
            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi</artifactId>
                <version>${poi.version}</version>
            </dependency>
            <dependency>
                <groupId>org.glassfish.jersey.media</groupId>
                <artifactId>jersey-media-json-jackson</artifactId>
                <version>${jackson.version}</version>
            </dependency>

            <dependency>
                <groupId>org.glassfish.jersey.core</groupId>
                <artifactId>jersey-client</artifactId>
                <version>${jackson.version}</version>
            </dependency>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>${gson.version}</version>
            </dependency>

        </dependencies>
    </dependencyManagement>

    <dependencies>

        <!-- JAVAEE 7 API -->
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Logging -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j-log4j12.version}</version>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>${guava.version}</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
        </dependency>

    </dependencies>

</project>

submodule pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>REDACTED</artifactId>
        <groupId>REDACTED</groupId>
        <version>1.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>REDACTED</artifactId>

    <build>
        <resources>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>jasper/**/*</exclude>
                    <exclude>fonts/**/*</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources/fonts</directory>
                <targetPath>fonts/</targetPath>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skipTests>false</skipTests>
                    <skip>false</skip>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jasperreports-maven-plugin</artifactId>
                <version>1.0-beta-2</version>
                <configuration>
                    <sourceDirectory>src/main/resources/report</sourceDirectory>
                    <outputDirectory>${project.build.directory}/classes/report</outputDirectory>
                </configuration>
               <executions>
                    <execution>
                        <goals>
                            <goal>compile-reports</goal>
                        </goals>
                        <phase>compile</phase>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>net.sf.jasperreports</groupId>
                        <artifactId>jasperreports</artifactId>
                        <version>4.5.1</version>
                        <exclusions>
                            <exclusion>
                                <artifactId>jdtcore</artifactId>
                                <groupId>eclipse</groupId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                    <dependency>
                        <groupId>xerces</groupId>
                        <artifactId>xercesImpl</artifactId>
                        <version>2.8.1</version>
                    </dependency>
                    <dependency>
                        <groupId>log4j</groupId>
                        <artifactId>log4j</artifactId>
                        <version>1.2.14</version>
                    </dependency>
                    <dependency>
                        <groupId>xml-apis</groupId>
                        <artifactId>xml-apis</artifactId>
                        <version>1.4.01</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

    <profiles>

        <profile>
            <id>REDACTED</id>
            <build>
                <resources>
                    <resource>
                        <filtering>true</filtering>
                        <directory>src/main/resources</directory>
                        <excludes>
                            <exclude>jasper/**/*</exclude>
                            <exclude>fonts/**/*</exclude>
                        </excludes>
                    </resource>
                    <resource>
                        <directory>src/main/resources/fonts</directory>
                        <targetPath>fonts/</targetPath>
                    </resource>
                </resources>

                <plugins>
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-resources</id>
                                <phase>compile</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${basedir}/target/classes/META-INF</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>src/main/resources/META-INF/REDACTED</directory>
                                            <filtering>true</filtering>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.0.2</version>
                        <configuration>
                            <excludes>
                                Buch of excluded locations for finders, not related to tests
                            </excludes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>REDACTED</id>
            <build>
                <resources>
                    <resource>
                        <filtering>true</filtering>
                        <directory>src/main/resources</directory>
                        <excludes>
                            <exclude>jasper/**/*</exclude>
                            <exclude>fonts/**/*</exclude>
                        </excludes>
                    </resource>
                    <resource>
                        <directory>src/main/resources/fonts</directory>
                        <targetPath>fonts/</targetPath>
                    </resource>
                </resources>

                <plugins>
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-resources</id>
                                <phase>compile</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${basedir}/target/classes/META-INF</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>src/main/resources/META-INF/REDACTED2</directory>
                                            <filtering>true</filtering>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.0.2</version>
                        <configuration>
                            <excludes>
                                Buch of excluded locations for finders, not related to tests
                            </excludes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

    </profiles>

    <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>${assertj-core.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- Arquillian junit -->
        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <version>${arquillian.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.arquillian.container</groupId>
            <artifactId>arquillian-container-spi</artifactId>
            <version>${arquillian.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- Arquillian persistence -->
        <dependency>
            <groupId>org.jboss.arquillian.extension</groupId>
            <artifactId>arquillian-persistence-api</artifactId>
            <version>${arquillian_persistence.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- Glassfish Remote -->
        <dependency>
            <groupId>org.jboss.arquillian.container</groupId>
            <artifactId>arquillian-glassfish-remote-3.1</artifactId>
            <version>${arq.version-glassfish-remote}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.shrinkwrap.resolver</groupId>
            <artifactId>shrinkwrap-resolver-depchain</artifactId>
            <version>${shrinkwrap-resolver-depchain.version}</version>
            <scope>test</scope>
            <type>pom</type>
        </dependency>

        <!-- HIBERNATE -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-envers</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Jasper Reports -->
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fatboyindustrial.gson-javatime-serialisers</groupId>
            <artifactId>gson-javatime-serialisers</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.2</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

</project>

编辑:

I, 运行 mvn help:effective-pom -Doutput=effective-pom-results.xml 命令,它让我知道了很多将 sip 设置为 true 的地方。我该如何解决?我是否必须手动查找这些地方并设置这些属性?我不能在这里包含它,因为它有 1,8k 行,如果有必要我可以将它上传到一些主机

至主要 pom.xml 我在 maven-compiler-plugin 工件下添加了执行:

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-testCompile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

并在同一个 pom 的属性中:

 <properties>

        <maven.test.skip>false</maven.test.skip>
        <skipIntTests>false</skipIntTests>
        <skipTests>false</skipTests>

感谢@j-woodchuck 和@antoniosss 我已经弄明白了

的研究结果

mvn help:effective-pom -Doutput=effective-pom-results.xml

生成有效 pom 的命令。