微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 Java11 和 Maven,尽量避免 jacoco 和 surefire 退出错误,并在 Mac 上运行 jacoco 测试覆盖

如何解决使用 Java11 和 Maven,尽量避免 jacoco 和 surefire 退出错误,并在 Mac 上运行 jacoco 测试覆盖

这似乎是与 Mac、Java11 相关的问题。我正在尝试将源代码和目标作为 Java8 运行,但我的运行时是 java 11

Java HotSpot(TM) 64 位服务器 VM 18.9(构建 11.0.6+8-LTS,混合模式)

Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T14:49:05-05:00) Maven 主页:/Users/user/Documents/tools/apache-maven-3.5.3 Java 版本:11.0.6,供应商:Oracle Corporation Java 主页:/Library/Java/JavaVirtualMachines/jdk-11.0.6.jdk/Contents/Ho

Jacoco 的问题

现在有了这个配置,我无法运行 jacoco,

错误是:由于缺少执行数据文件而跳过 JaCoCo 执行。

Surefire 错误问题

我还必须把它放在我的 pom.xml 中以避免下面的错误

添加了片段。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <!-- Remove snippet below,fix jacoco?  But get jdk11 error? -->
    <version>2.21.0</version>
    <configuration>
        <forkCount>3</forkCount>
        <reuseForks>true</reuseForks>
        <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
    </configuration>
</plugin>

现在,我收到此错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project pri-prospect-management-batch: There are test failures.
[ERROR] 
[ERROR] Please refer to /Users/user/git-main5/pri-prospect-management-batch/app/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump,[date]-jvmrun[N].dump and [date].dumpstream.
[ERROR] The forked VM terminated without properly saying goodbye. VM crash or System.exit called?

[ERROR] Process Exit Code: 134
[ERROR]     at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:669)

所以我试图运行 jacoco、java11、surefire 没有错误

配置:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven-clean-plugin-version>2.5</maven-clean-plugin-version>
    <maven-compiler-plugin-version>3.3</maven-compiler-plugin-version>
    <maven-dependency-plugin-version>2.8</maven-dependency-plugin-version>
    <maven-install-plugin-version>2.4</maven-install-plugin-version>
    <maven-jar-plugin-version>2.4</maven-jar-plugin-version>
    <maven-resources-plugin-version>2.6</maven-resources-plugin-version>
    <maven-surefire-plugin-version>2.12.4</maven-surefire-plugin-version>
    <maven-war-plugin-version>2.2</maven-war-plugin-version>
    <maven-ear-plugin-version>2.8</maven-ear-plugin-version>
    <java.source.version>1.8</java.source.version>
    <java.target.version>1.8</java.target.version>
    <org.springframework.version>4.3.8.RELEASE</org.springframework.version>
    <jacoco.version>0.7.9</jacoco.version>
    <jackson.version>2.11.2</jackson.version>
</properties>

...

雅可

 <plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>${jacoco.version}</version>
    <executions>
        <execution>
            <id>prepare-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
        <execution>
            <id>post-unit-test</id>
            <phase>test</phase>
            <goals>
                <goal>report</goal>
            </goals>
            <configuration>
                <dataFile>target/jacoco.exec</dataFile>
                <outputDirectory>target/jacoco-ut</outputDirectory>
            </configuration>
        </execution>
    </executions>
    <configuration>
        <excludes>
        </excludes>
    </configuration>
</plugin>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。