-1

我在一个小项目中使用 maven 3.3 + scala 2.10。scalatest 框架运行良好。但是,当我切换到 scala 2.11 并将所有依赖项替换为 2.11 时:

    <dependency>
        <groupId>org.scalatest</groupId>
        <artifactId>scalatest_2.11</artifactId>
        <version>2.2.6</version>
        <scope>test</scope>
    </dependency>

我第一次运行 mvn test 它抛出了这个错误:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- scalatest-maven-plugin:1.0:test (test) @ spookystuff-core ---
An exception or error caused a run to abort. This may have been caused by a problematic custom reporter.
java.lang.NoSuchMethodError: scala.runtime.ObjectRef.create(Ljava/lang/Object;)Lscala/runtime/ObjectRef;
    at org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:2347)
    at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1044)
    at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1043)
    at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:2722)
    at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1043)
    at org.scalatest.tools.Runner$.main(Runner.scala:860)
    at org.scalatest.tools.Runner.main(Runner.scala)

有人可以解释它是什么意思,以及如何解决它吗?

4

3 回答 3

2

如果你使用 Maven 和 Scala,不要scalatest_2.11; 相反,使用类似的东西

<properties>
  <encoding>UTF-8</encoding>
  <scala.binary.version>2.11</scala.binary.version>
</properties>
...
  <artifactId>scalatest_${scala.binary.version}</artifactId>

否则,您会经常遇到此类问题。

于 2016-12-28T22:46:12.217 回答
0

我使用了 maven 3.xx 和 scala 2.11.12

解决方案对我有用,希望它也对你有用:

您需要将这些依赖项添加到您的块中到您的 pom.xml

<dependency>
  <groupId>org.scala-lang</groupId>
  <artifactId>scala-library</artifactId>
  <version>2.11.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.scalatest/scalatest -->
<dependency>
  <groupId>org.scalatest</groupId>
  <artifactId>scalatest_2.11</artifactId>
  <version>3.2.0-SNAP10</version>
  <scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.scalacheck/scalacheck -->
<dependency>
  <groupId>org.scalacheck</groupId>
  <artifactId>scalacheck_2.11</artifactId>
  <version>1.15.1</version>
  <scope>test</scope>
</dependency>

并通过将这些插件添加到块中来禁用surefire并启用scalatest

<plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <version>3.4.0</version>
    <configuration>
      <scalaVersion>2.11.12</scalaVersion>
    </configuration>
  </plugin>
  <!-- disable surefire -->
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.7</version>
    <configuration>
      <skipTests>true</skipTests>
    </configuration>
  </plugin>
  <!-- enable scalatest -->
  <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>test</id>
        <goals>
          <goal>test</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
于 2021-03-05T10:26:36.900 回答
-1

好的,我发现了问题。做一个 mvn 依赖:树表明一个库没有随 scala 2.11 一起提供,当编译它的依赖时仍然解析为 2.10。

解决方案是排除它的依赖:

    <dependency>
        <groupId>com.github.mdr</groupId>
        <artifactId>ascii-graphs_2.10</artifactId>
        <version>0.0.6</version>
        <exclusions>
            <exclusion>
                <groupId>org.scala-lang</groupId>
                <artifactId>scala-library</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

一切都变得正常。

于 2016-12-28T21:14:09.913 回答