【问题标题】:Project running for mvn test but not running for mvn test -P<<profile_name>>项目正在运行 mvn test 但未运行 mvn test -P<<profile_name>>
【发布时间】:2018-07-16 08:19:07
【问题描述】:

在发布这个问题之前,我已经阅读了很多文章和 SO 帖子。我创建了 2 个 Maven 配置文件,每个环境一个。当我通过 Eclipse 的 Run As > Maven 测试运行我的 pom.xml 时,会执行测试。但是当我通过运行配置执行它时,为此目的,我创建了一个名为“测试项目”的运行配置,它的 Maven 目标设置为“测试”,配置文件设置为“暂存”,执行正在抛出

分叉进程中出现错误 [错误] com/beust/jcommander/ParameterException:不支持的 major.minor 版本 52.0 [错误] org.apache.maven.surefire.booter.SurefireBooterForkException:分叉进程中出现错误 [错误] com/beust/jcommander/ParameterException:不支持的major.minor 52.0版

如果是 java 版本问题,那么当我执行 Run As > Maven 测试时它不应该执行。

这是我的 pom.xml

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.sample</groupId>
<artifactId>TestProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>TestProject</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<profiles>
    <profile>
        <id>staging</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.20</version>
                    <configuration>
                        <suiteXmlFiles>
                            <suiteXmlFile>testng.xml</suiteXmlFile>
                        </suiteXmlFiles>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

    <profile>
        <id>prod</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.20</version>
                    <configuration>
                        <suiteXmlFiles>
                            <suiteXmlFile>testng2.xml</suiteXmlFile>
                        </suiteXmlFiles>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

<dependencies>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.11</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.uncommons/reportng -->
    <dependency>
        <groupId>org.uncommons</groupId>
        <artifactId>reportng</artifactId>
        <version>1.1.4</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

</dependencies>

testng.xml 和 testng2.xml 都是相似的,只是参数值不同。 这是我的 testng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite verbose="0" name="Test Project suite">
     <parameter name="env" value="staging" /> 
    <test name="Test Project sample tests">
        <classes>
            <class name="com.sample.TestProject.AppTest" />
        </classes>
    </test>
</suite> 

【问题讨论】:

    标签: maven testng maven-profiles


    【解决方案1】:

    请添加如下所示的属性,然后重试。

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    

    这将导致所需的 JDK 版本设置为 1.8。如果你不提供这个,那么默认情况下,Maven 会采用 1.5 兼容。

    当您通过命令行运行时(使用mvn test),这将是必需的。该错误是对这个问题的重复。

    当您执行Run as &gt; maven test 时,我猜测您的 IDE 提供的 JDK 会生效(我没有办法在技术上证实这一理论)。

    有关其他上下文,您也可以参考this stackoverflow 帖子。

    【讨论】:

      猜你喜欢
      • 2021-01-16
      • 1970-01-01
      • 2019-02-19
      • 1970-01-01
      • 2015-12-21
      • 1970-01-01
      • 2021-09-08
      • 2018-09-26
      • 2021-03-04
      相关资源
      最近更新 更多