【问题标题】:Maven modules will not find dependencies with scalatestMaven 模块将找不到具有 scalatest 的依赖项
【发布时间】:2014-11-05 12:36:14
【问题描述】:

在使用 scalatest 时,我遇到了一个奇怪的问题。我有一个包含多个模块的 Maven 项目。如果我直接在模块中执行mvn test。它可以正常工作,但是如果我在根文件夹中执行此操作,它会在编译时抱怨缺少包(依赖项)。

我的配置如下:

    <dependency>
      <groupId>org.scalatest</groupId>
      <artifactId>scalatest_${scala.shortversion}</artifactId>
      <version>3.0.0-SNAP2</version>
    </dependency>
    <dependency>
      <groupId>org.scalatest</groupId>
      <artifactId>scalatest-maven-plugin</artifactId>
      <version>1.0</version>
    </dependency>

插件配置:

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.7</version>
            <configuration>
              <skipTests>true</skipTests>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest-maven-plugin</artifactId>
            <version>1.0</version>
            <configuration>
              <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
              <junitxml>.</junitxml>
              <filereports>WDF TestSuite.txt</filereports>
            </configuration>
            <executions>
              <execution>
                <id>scala-test</id>
                <goals>
                  <goal>test</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

如果我从maven-scala-plugin 中删除goals,它将编译但scalatest 将找不到测试源并以No tests were executed. 退出:

        <plugin>
            <version>2.15.2</version>
            <groupId>org.scala-tools</groupId>
            <artifactId>maven-scala-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>compile</goal>
                  <goal>testCompile</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <scalaVersion>${scala.version}</scalaVersion>
            </configuration>
        </plugin>

关于我做错了什么有什么想法吗?!

干杯

【问题讨论】:

    标签: scala maven configuration scalatest


    【解决方案1】:

    没有看到你所有的 pom 就很难说,但一般来说: 在根 Pom 中定义 dependencyManagement 部分中的所有依赖项,pluginManagement 部分中的插件及其配置。在子 pom 中仅定义您需要的那些插件和依赖项。

    请记住,xxxManagement 部分仅构建共享定义,一种根配置。您仍然需要在 pluginsdependencies 部分中定义您需要的内容,但您可以省略版本和配置元素。

    这将允许您的所有子 pom 在所有模块中运行测试。

    【讨论】:

    • 我继承了这个项目,不得不清理很多东西。当我在根 pom 中重新组织 pluginManagement 时,我的问题得到了解决。感谢您的提示!