【问题标题】:Multimodules maven project: scalatest fails in root folderMultimodules maven项目:scalatest在根文件夹中失败
【发布时间】: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>

谢谢。

【问题讨论】:

    标签: scala maven scalatest


    【解决方案1】:

    好的,我相信我找到了解决方案。 mvn clean 测试有效,所以这就是我所做的:基本上,在根 pom 中,我说要忽略来自父级的配置,模块 A 中的相同内容,然后重新定义模块 B 中的所有内容。我不得不调整在 scalatest 中使用什么目标/id,但是在根目录或 B 模块目录中使用“mvn test”。

    在父 pom 中跳过了 Surefire 测试。

    Myproject 和一个 pom.xml,在 build/plugins 下:

        <plugin>
                <groupId>org.scalatest</groupId>
                <artifactId>scalatest-maven-plugin</artifactId>
                <inherited>false</inherited>
                <executions>
                    <execution>
                        <id>test</id>
                        <phase>none</phase>
                    </execution>
                </executions>
            </plugin>
    

    在build/plugins下的B pom.xml中:

    <plugin>
                <groupId>org.scalatest</groupId>
                <artifactId>scalatest-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>scala-test</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                    <junitxml>.</junitxml>
                    <skipTests>false</skipTests>
                </configuration>
            </plugin> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-06
      • 2013-01-26
      • 1970-01-01
      • 1970-01-01
      • 2013-10-16
      • 1970-01-01
      • 2015-05-10
      相关资源
      最近更新 更多