英文:
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:
<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 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?
专注分享java语言的经验与见解,让所有开发者获益!
评论