Maven:在生命周期中跳过test-compile?

问题描述 投票:20回答:4

我通过使用此设置设置了使用test-jar和普通jar构建的项目:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

这个问题是每当我升级pom中的项目版本时,我需要使用测试进行构建,否则maven将无法在test-compile短语中找到具有正确版本的测试jar。很多时候我只想跳过测试,但由于测试罐丢失,test-compilephrase将失败。

我试图使用-Dmaven.test.skip=true,但这似乎没有跳过test-compile短语。有没有办法跳过这个?

testing build maven compilation skip
4个回答
41
投票
$ mvn clean install -Dmaven.test.skip=true \
      -Dmaven.site.skip=true -Dmaven.javadoc.skip=true

36
投票

如果要跳过测试源的编译,可以尝试适当地配置maven compiler plugin。不建议这样做。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <executions>
                <execution>
                    <id>default-testCompile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </execution>
            </executions>
        </plugin>

1
投票

只需添加-Dmaven.test.skip。它甚至不会编译测试


0
投票

上面的解决方案给了我未知的生命周期阶段“.test.skip = true”错误。

这是我在https://maven.apache.org/plugins-archives/maven-surefire-plugin-2.12.4/examples/skipping-test.html的工作指令

mvn install -DskipTests

© www.soinside.com 2019 - 2024. All rights reserved.