首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多模块maven项目:根文件夹中的scalatest失败

多模块maven项目:根文件夹中的scalatest失败
EN

Stack Overflow用户
提问于 2020-12-31 16:55:05
回答 1查看 232关注 0票数 1

我试图在一个多模块scala项目上执行测试:

代码语言:javascript
复制
Myproject 
    -module A
    -module B

模块A是前端,B是带有测试的scala项目。当我进入Myproject/B并执行mvn scalatest:test (或mvn测试)时,它们将很好地执行。然而,如果我尝试从根文件夹,我得到一个错误,阻止我执行一个mvn安装,除非我跳过测试(这是不好的)。

错误是:无法找到或加载主类org.scalatest.tools.Runner

显然,scalatest在根文件夹中寻找不存在的测试类,它实际上只有主pom.xml,所有源都在子模块A和B中

B也有子模块,但是如果我直接在B目录下运行maven命令,那么那里的测试就会得到执行和发现。实际上,问题是当我在根目录下时。编译甚至sbt-complier:testCompile运行良好,几乎立即失败的是scalatest:test

代码语言:javascript
复制
 [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中提取:

代码语言:javascript
复制
<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>

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-04 10:57:54

好吧,我想我找到了解决办法。mvn干净测试可以工作,所以我就是这样做的:基本上,在根pom中,我说忽略从父模块开始的配置,模块A中的配置相同,然后修改模块B中的所有内容。我不得不调整一下在最可缩放的目录中使用的目标/id,但是使用根目录或B模块目录中的"mvn测试“可以工作。

准火测试跳过了家长的测试。

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

代码语言:javascript
复制
    <plugin>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest-maven-plugin</artifactId>
            <inherited>false</inherited>
            <executions>
                <execution>
                    <id>test</id>
                    <phase>none</phase>
                </execution>
            </executions>
        </plugin>

在构建/插件下的B pom.xml中:

代码语言:javascript
复制
<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> 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65523581

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档