我使用maven 3.3 + scala 2.10进行小型项目。最新的框架非常有效。但是,当我切换到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)
有人可以解释它意味着什么,以及如何解决它?
答案 0 :(得分:1)
如果您使用带Scala的Maven,不要写scalatest_2.11
;相反,使用像
<properties>
<encoding>UTF-8</encoding>
<scala.binary.version>2.11</scala.binary.version>
</properties>
...
<artifactId>scalatest_${scala.binary.version}</artifactId>
否则,您会经常遇到这样的问题。
答案 1 :(得分:0)
我使用了 maven 3.x.x 和 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>
答案 2 :(得分:-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>
一切都变得正常了。