首页 > 解决方案 > Maven scala scoverage 尝试为其他模块拉包

问题描述

我有一个具有以下架构的多模块 Maven 项目

root

 - module-A
 - module-B (depends on A)
 - module-C1 (depends on B)
 - module-C2 (depends on B)
 ...
 - module-Cn (depends on B)

它的 scoverage-maven-plugin 配置如下。

<plugin>
    <groupId>org.scoverage</groupId>
    <artifactId>scoverage-maven-plugin</artifactId>
    <version>${scoverage.plugin.version}</version>
    <configuration>
        <scalaVersion>${scala.version}</scalaVersion>
        <aggregate>true</aggregate>
    </configuration>
    <executions>
        <execution>
            <id>report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
    </executions>
</plugin>

scoverage.plugin.version = 1.4.1 scala.version = 2.11.11

mvn clean package如果我在根项目的本地午餐,它会按预期工作,但在 CI 工作流程中(如果有用的话,竹子),模块 A 和 B 运行良好,但在 C1 上我收到以下错误:

14-May-2020 14:23:41    [INFO] >>> scoverage-maven-plugin:1.4.1:report (report) > [scoverage]test @ C1 >>>
14-May-2020 14:23:41    [INFO] 
14-May-2020 14:23:41    [INFO] --- scoverage-maven-plugin:1.4.1:pre-compile (report) @ C1 ---
14-May-2020 14:23:41    [INFO] Downloading from nexus: https://fakenexusurl.com/repository/all/module-B/1.0.0-SNAPSHOT/maven-metadata.xml
14-May-2020 14:23:41    [INFO] Downloading from nexus: https://fakenexusurl.com/repository/all/module-B/1.0.0-SNAPSHOT/module-B-1.0.0-SNAPSHOT.jar
14-May-2020 14:23:41    [INFO] ------------------------------------------------------------------------
14-May-2020 14:23:41    [INFO] Reactor Summary:
14-May-2020 14:23:41    [INFO] 
14-May-2020 14:23:41    [INFO] root .......................................... SUCCESS [  3.610 s]
14-May-2020 14:23:41    [INFO] module-A ................................... SUCCESS [01:38 min]
14-May-2020 14:23:41    [INFO] modulde-B ............................. SUCCESS [01:30 min]
14-May-2020 14:23:41    [INFO] module-C1 ........................... FAILURE [01:37 min]
14-May-2020 14:23:41    [INFO] module-C2 ........................... SKIPPED
14-May-2020 14:23:41    [INFO] ------------------------------------------------------------------------
14-May-2020 14:23:41    [INFO] BUILD FAILURE
14-May-2020 14:23:41    [INFO] ------------------------------------------------------------------------
14-May-2020 14:23:41    [INFO] Total time: 04:50 min
14-May-2020 14:23:41    [INFO] Finished at: 2020-05-14T14:23:41Z
14-May-2020 14:23:42    [INFO] Final Memory: 85M/1627M
14-May-2020 14:23:42    [INFO] ------------------------------------------------------------------------
14-May-2020 14:23:42    [ERROR] Failed to execute goal on project module-C1: Could not resolve dependencies for project group:module-C1:jar:1.0.0-SNAPSHOT: Could not find artifact group:module-B:jar:1.0.0-SNAPSHOT in nexus (https://fakenexusurl.com/repository/all/) -> [Help 1]

我看到它正在尝试从公司的 nexus 下载模块 B,当然,它不存在,因为我们没有发布此快照。但我不明白为什么它试图下载应该在同一个项目的另一个模块中查看的依赖项。以及为什么它对依赖于 A 的 B 不做同样的事情,如果文件除了模块名称和依赖项之外是相等的。

所有使用的依赖项都在 root 中声明,dependencyManagment插件在pluginManagment

CI 工作流程对我们来说是一个黑匣子,我们不知道他们是否使用了任何额外的配置文件。我们唯一知道的是启动mvn clean package命令。

标签: scalamavencode-coverage

解决方案


覆盖流程创建了 Maven 流程的一个分支,并重新运行所有流程直到测试。在这个分支中,模块之间的依赖关系没有得到很好的管理,所以从干净的执行中正确执行它的唯一方法是使用命令:

mvn clean install scoverage:report

将安装更改为打包、部署或任何需要报告的元素。这将强制 mavenscoverage:report在每个模块的末尾执行,防止出现不需要的行为。

在这个线程中找到了信息。


推荐阅读