Maven多线程构建问题

huangapple 未分类评论46阅读模式
英文:

Maven multithreaded build problems

问题

我继承了一个使用 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</relativePath>
    </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 中也被列为 "test" 依赖项。

当我进行多线程构建时,有时会出现以下错误:

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 吗?

英文:

I've inherited a project that uses maven 3.6.2. It compiles fine every time without fail when I do a

 mvn clean install

However, when I try to speed up the builds and make them multhreaded

mvn -T C1 clean install

I get all kinds of things that don't make sense. At first I thought it was a dependency problem, but that doesn't seem to be it, i don't think.

Here's a pom file:

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

junit and hamcrest are ALSO listed as "test" dependencies in the parent poms.

When I build multithreaded, I sometimes get

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

The contents of the dump file are:

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)

This doesn't make sense to me. the pom file SAYS junit (and hamcrest) are dependencies. and this works SOMETIMES.it works fine single threaded. How stable is the multithreaded stuff in maven?

More importantly, what am i missing? shouldn't it be able to find the RunListener?

huangapple
  • 本文由 发表于 2020年7月27日 04:26:16
  • 转载请务必保留本文链接:https://java.coder-hub.com/63105346.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定