首页 > 解决方案 > Maven多线程构建问题

问题描述

我继承了一个使用 maven 3.6.2 的项目。当我做一个时,它每次都编译得很好

 mvn clean install

但是,当我尝试加快构建并使它们多线程时

mvn -T C1 clean install

我得到了各种没有意义的东西。起初我认为这是一个依赖问题,但似乎不是这样,我不认为。

这是一个pom文件:

<project
    <modelVersion>4.0.0</modelVersion>
    <artifactId>project-components-hadoop</artifactId>
    <version>0.0.0.0_EXPERIMENTAL-VERSION</version>
    <name>project-hadoop</name>
    <packaging>jar</packaging>
    <parent>
        <groupId>com.mycompany</groupId>
        <artifactId>project-release-dependencies</artifactId>
        <version>0.0.0.0_EXPERIMENTAL-VERSION</version>
        <relativePath>../../project-core/project-release-dependencies</relativeP
ath>
    </parent>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-core</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>
        ...

junit 和 hamcrest 在父 pom 中也被列为“测试”依赖项。

当我构建多线程时,我有时会得到

15:54:06  [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.20:test (default-test) on project project-hadoop: There are test failures.
15:54:06  [ERROR] 
15:54:06  [ERROR] Please refer to [directory]/target/surefire-reports for the individual test results.
15:54:06  [ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
15:54:06  [ERROR] There was an error in the forked process
15:54:06  [ERROR] org/junit/runner/notification/RunListener
15:54:06  [ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
15:54:06  [ERROR] org/junit/runner/notification/RunListener

转储文件的内容是:

java.lang.NoClassDefFoundError: org/junit/runner/notification/RunListener
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
        at java.lang.Class.getConstructor0(Class.java:3075)
        at java.lang.Class.getConstructor(Class.java:1825)
        at org.apache.maven.surefire.util.ReflectionUtils.getConstructor(ReflectionUtils.java:79)

这对我来说没有意义。pom文件说junit(和hamcrest)是依赖项。这有时会起作用。它可以在单线程中正常工作。maven中的多线程东西有多稳定?

更重要的是,我错过了什么?它不应该能够找到 RunListener 吗?

标签: javamultithreadingmavenjunit4hamcrest

解决方案


推荐阅读