在Intellij中升级到Scala 2.12版本后,Scala类不会加载

时间:2018-05-25 06:06:02

标签: scala intellij-idea

我已将Scala版本从2.11+升级到2.12。

但从那时起,我所有的Gatling测试都在Intellij中崩溃了。我使用的是2017.3版。

我收到此消息:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at io.gatling.mojo.MainWithArgsInFile.runMain(MainWithArgsInFile.java:50)
    at io.gatling.mojo.MainWithArgsInFile.main(MainWithArgsInFile.java:33)
Caused by: java.lang.NoClassDefFoundError: scala/math/Ordered$class
    at scala.tools.nsc.settings.MutableSettings$Setting.<init>(MutableSettings.scala:356)
    at scala.tools.nsc.settings.MutableSettings$StringSetting.<init>(MutableSettings.scala:497)
    at scala.tools.nsc.settings.MutableSettings.StringSetting(MutableSettings.scala:231)
    at scala.tools.nsc.settings.MutableSettings.PathSetting(MutableSettings.scala:235)
    at scala.tools.nsc.settings.MutableSettings.PathSetting(MutableSettings.scala:19)
    at scala.tools.nsc.settings.StandardScalaSettings$class.$init$(StandardScalaSettings.scala:21)
    at scala.tools.nsc.settings.MutableSettings.<init>(MutableSettings.scala:20)
    at scala.tools.nsc.Settings.<init>(Settings.scala:12)
    at xsbt.CachedCompiler0.<init>(CompilerInterface.scala:68)
    at xsbt.CompilerInterface.newCompiler(CompilerInterface.scala:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:101)
    at sbt.compiler.AnalyzingCompiler.newCachedCompiler(AnalyzingCompiler.scala:56)
    at sbt.compiler.AnalyzingCompiler.newCachedCompiler(AnalyzingCompiler.scala:51)
    at sbt.compiler.CompilerCache$$anon$2.apply(CompilerCache.scala:47)
    at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:39)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileScala$1$1.apply$mcV$sp(AggressiveCompile.scala:95)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileScala$1$1.apply(AggressiveCompile.scala:95)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileScala$1$1.apply(AggressiveCompile.scala:95)
    at sbt.compiler.AggressiveCompile.sbt$compiler$AggressiveCompile$$timed(AggressiveCompile.scala:168)
    at sbt.compiler.AggressiveCompile$$anonfun$3.compileScala$1(AggressiveCompile.scala:94)
    at sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:142)
    at sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:84)
    at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:66)
    at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:64)
    at sbt.inc.IncrementalCommon.cycle(IncrementalCommon.scala:31)
    at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:62)
    at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:61)
    at sbt.inc.Incremental$.manageClassfiles(Incremental.scala:89)
    at sbt.inc.Incremental$.compile(Incremental.scala:61)
    at sbt.inc.IncrementalCompile$.apply(Compile.scala:54)
    at sbt.compiler.AggressiveCompile.compile2(AggressiveCompile.scala:159)
    at sbt.compiler.AggressiveCompile.compile1(AggressiveCompile.scala:68)
    at com.typesafe.zinc.Compiler.compile(Compiler.scala:201)
    at com.typesafe.zinc.Compiler.compile(Compiler.scala:183)
    at com.typesafe.zinc.Compiler.compile(Compiler.scala:174)
    at com.typesafe.zinc.Compiler.compile(Compiler.scala:165)
    at io.gatling.compiler.ZincCompiler$$anonfun$7.apply(ZincCompiler.scala:154)
    at io.gatling.compiler.ZincCompiler$$anonfun$7.apply(ZincCompiler.scala:154)
    at scala.util.Try$.apply(Try.scala:161)
    at io.gatling.compiler.ZincCompiler$delayedInit$body.apply(ZincCompiler.scala:154)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.collection.immutable.List.foreach(List.scala:318)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
    at scala.App$class.main(App.scala:71)
    at io.gatling.compiler.ZincCompiler$.main(ZincCompiler.scala:36)
    at io.gatling.compiler.ZincCompiler.main(ZincCompiler.scala)
    ... 6 more
Caused by: java.lang.ClassNotFoundException: scala.math.Ordered$class
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 59 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.034 s
[INFO] Finished at: 2018-05-25T16:56:02+11:00
[INFO] Final Memory: 15M/220M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.gatling:gatling-maven-plugin:2.2.1:execute (default-cli) on project dead_url_spotter: Gatling failed. Simulations compilation failed. Process exited with an error: -1 (Exit value: -1) -> [Help 1]

我试过了:

  • 再次建设项目
  • 同步项目
  • 重启Intellij
  • Purgin Maven缓存

但我一遍又一遍地重现这个问题。

有没有人对此有所了解?

提前致谢。

编辑:我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>dead_url_spotter</groupId>
    <artifactId>dead_url_spotter</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <scala.version>2.12.0</scala.version>
        <encoding>UTF-8</encoding>

        <gatling.version>2.3.0</gatling.version>

        <scala-maven-plugin.version>3.3.2</scala-maven-plugin.version>
        <gatling.maven.version>2.2.1</gatling.maven.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.gatling</groupId>
                <artifactId>gatling-app</artifactId>
                <version>${gatling.version}</version>
            </dependency>
            <dependency>
                <groupId>io.gatling</groupId>
                <artifactId>gatling-recorder</artifactId>
                <version>${gatling.version}</version>
            </dependency>
            <dependency>
                <groupId>io.gatling.highcharts</groupId>
                <artifactId>gatling-charts-highcharts</artifactId>
                <version>${gatling.version}</version>
            </dependency>
            <dependency>
                <groupId>org.scala-lang</groupId>
                <artifactId>scala-library</artifactId>
                <version>${scala.version}</version>
            </dependency>
            <dependency>
                <groupId>com.typesafe.scala-logging</groupId>
                <artifactId>scala-logging_2.12</artifactId>
                <version>3.9.0</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>LATEST</version>
        </dependency>
        <dependency>
            <groupId>io.gatling.highcharts</groupId>
            <artifactId>gatling-charts-highcharts</artifactId>
        </dependency>
        <dependency>
            <groupId>io.gatling</groupId>
            <artifactId>gatling-app</artifactId>
        </dependency>
        <dependency>
            <groupId>io.gatling</groupId>
            <artifactId>gatling-recorder</artifactId>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
        </dependency>
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>org.json</artifactId>
            <version>LATEST</version>
        </dependency>
        <dependency>
            <groupId>com.cedarsoftware</groupId>
            <artifactId>json-io</artifactId>
            <version>4.9.8</version>
        </dependency>
        <dependency>
            <groupId>org.jmxtrans</groupId>
            <artifactId>jmxtrans</artifactId>
            <version>263</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.11.2</version>
        </dependency>
    </dependencies>

    <build>
        <testSourceDirectory>src/test/java</testSourceDirectory>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>scala-maven-plugin</artifactId>
                    <version>${scala-maven-plugin.version}</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>io.gatling</groupId>
                <artifactId>gatling-maven-plugin</artifactId>
                <version>2.2.4</version>
                <configuration>
                    <jvmArgs>
                        <jvmArg>-Durl=http://localhost:9000</jvmArg>
                        <jvmArg>-DnumberOfUsers=10</jvmArg>
                        <jvmArg>-DnumberOfRepetitions=1</jvmArg>
                        <jvmArg>-DdurationMinutes=1</jvmArg>
                        <jvmArg>-DpauseBetweenRequestsMs=3000</jvmArg>
                        <jvmArg>-Ddebug=false</jvmArg>
                    </jvmArgs>
                    <configFolder>src/test/resources</configFolder>
                    <dataFolder>src/test/resources/data</dataFolder>
                    <resultsFolder>target/gatling/results</resultsFolder>
                    <bf>src/test/resources/bodies</bf>
                    <simulationsFolder>src/test/scala</simulationsFolder>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                        <configuration>
                            <args>
                                <arg>-Ybackend:GenBCode</arg>
                                <arg>-Ydelambdafy:method</arg>
                                <arg>-target:jvm-1.8</arg>
                                <arg>-deprecation</arg>
                                <arg>-feature</arg>
                                <arg>-unchecked</arg>
                                <arg>-language:implicitConversions</arg>
                                <arg>-language:postfixOps</arg>
                            </args>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.20.1</version>
                <configuration>
                    <skip>${skip.selenium.tests}</skip>
                    <parallel>none</parallel>
                    <threadCount>1</threadCount>
                    <reuseForks>false</reuseForks>
                    <disableXmlReport>false</disableXmlReport>
                </configuration>
                <executions>
                    <execution>
                        <id>runSeleniumTests</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

2 个答案:

答案 0 :(得分:2)

从错误看起来你正在使用Maven。在_2.11中查找依赖项中的任何pom.xml,并修复它们。为避免将来再次出现此问题,请添加scala.binary.version媒体资源并在_${scala.binary.version}中使用artifactId(例如,请参阅Spark pom.xml)。

答案 1 :(得分:0)

升级 scalamaven 时遇到此问题。

降级到 maven 3.6.3 解决了这个问题。

sdk install maven 3.6.3

此外,还应检查 scala-maven-plugin

<scala.compiler.version>3.4.6</scala.compiler.version>

<artifactId>scala-maven-plugin</artifactId>
<version>${scala.compiler.version}</version>