【发布时间】:2021-04-07 22:31:11
【问题描述】:
我正在尝试对多模块 scala 项目执行测试:
Myproject
-module A
-module B
模块 A 是前端,B 是带有测试的 scala 项目。当我进入 Myproject/B 并执行 mvn scalatest:test (或 mvn test)时,它们执行得很好。但是,如果我从根文件夹尝试,我会收到一个错误,阻止我执行 mvn install,除非我跳过测试(这很糟糕)。
错误是:无法找到或加载主类org.scalatest.tools.Runner。
显然,scalatest 正在根文件夹中寻找不存在的测试类,实际上只有主 pom.xml,所有源都在子模块 A 和 B 中
B 也有子模块,但是如果我直接在 B 目录下运行 maven 命令,那里的测试会被执行并发现很好。真的,问题是当我在根目录下时。编译甚至 sbt-complier:testCompile 运行良好,实际上是 scalatest:test 几乎立即失败:
[INFO] Myproject.......................................... FAILURE [ 1.108 s]
[INFO] B................................................... SKIPPED
[INFO] A................................................... SKIPPED
[ERROR] Failed to execute goal org.scalatest:scalatest-maven-plugin:2.0.0:test (test) on project Myproject: There are test failures -> [Help 1]
从 Myproject 中的 pom.xml 中提取:
<project>
<groupId>.....</groupId>
<artifactId>;;;;;;</artifactId>
<packaging>pom</packaging>
<description>Myproject</description>
<version>....</version>
<name>Myproject</name>
<modules>
<module>A</module>
<module>B</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.12</artifactId>
<version>${scalatest.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>com.google.code.sbt-compiler-maven-plugin</groupId>
<artifactId>sbt-compiler-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
<!-- I need to set that to true and override that in the pom.xml from the module B -->
</configuration>
</plugin>
</plugins>
</build>
</project>
谢谢。
【问题讨论】: