IntelliJ Idea Maven项目中Scala模块的Scala签名错误

时间:2021-03-16 22:55:10

Disclaimer: I am new to Scala and trying to create a sample Scala Maven project using simple scala archtype in IntelliJ IDEA. IntelliJ version is 14.1.2

免责声明:我是Scala的新手,并尝试使用IntelliJ IDEA中的简单scala archtype创建示例Scala Maven项目。 IntelliJ版本是14.1.2

Below is my pom file, I did change the Scala version to 2.11.6 from 2.7 which the archetype generates by default.

下面是我的pom文件,我确实将Scala版本从2.7改为2.11.6,原型默认生成。

<!-- language: lang-xml -->
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>learn.rxscala</groupId>
  <artifactId>rxscala-reactive-course-play</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <inceptionYear>2008</inceptionYear>
  <properties>
    <scala.version>2.11.6</scala.version>
    <slf4j.version>1.7.5</slf4j.version>
    <reactivex.version>0.23.0</reactivex.version>
    <rx.scala.compat.version>2.11</rx.scala.compat.version>
    <scala.async.version>0.9.2</scala.async.version>
  </properties>

  <repositories>
    <repository>
      <id>scala-tools.org</id>
      <name>Scala-Tools Maven2 Repository</name>
      <url>http://scala-tools.org/repo-releases</url>
    </repository>
  </repositories>

  <pluginRepositories>
    <pluginRepository>
      <id>scala-tools.org</id>
      <name>Scala-Tools Maven2 Repository</name>
      <url>http://scala-tools.org/repo-releases</url>
    </pluginRepository>
  </pluginRepositories>

  <dependencies>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>${scala.version}</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.10</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.specs</groupId>
      <artifactId>specs</artifactId>
      <version>1.2.5</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.reactivex</groupId>
      <artifactId>rxscala_${rx.scala.compat.version}</artifactId>
      <version>${reactivex.version}</version>
    </dependency>
    <dependency>
      <groupId>org.scala-lang.modules</groupId>
      <artifactId>scala-async_${rx.scala.compat.version}</artifactId>
      <version>${scala.async.version}</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${slf4j.version}</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>${slf4j.version}</version>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.17</version>
    </dependency>
  </dependencies>

  <build>
    <sourceDirectory>src/main/scala</sourceDirectory>
    <testSourceDirectory>src/test/scala</testSourceDirectory>
    <plugins>
      <plugin>
        <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>
          <args>
            <arg>-target:jvm-1.5</arg>
          </args>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.scala-tools</groupId>
        <artifactId>maven-scala-plugin</artifactId>
        <configuration>
          <scalaVersion>${scala.version}</scalaVersion>
        </configuration>
      </plugin>
    </plugins>
  </reporting>
</project>

On running Maven test, I keep getting following error -

在运行Maven测试时,我不断收到以下错误 -

[WARNING] error: error while loading JUnit4, Scala signature JUnit4 has wrong version
[WARNING]  expected: 5.0
[WARNING]  found: 4.1 in JUnit4.class

I am not sure how to fix this problem?

我不知道如何解决这个问题?

2 个解决方案

#1


Just make sure you use the up-to-date scala-archetype-simple, because IDEA requires new scala-archetype-simple to work with. But by default IDEA does not provide the correct scala-srchetype-simple to choose, you need to type in the right one by yourself.

只需确保使用最新的scala-archetype-simple,因为IDEA需要新的scala-archetype-simple才能使用。但默认情况下,IDEA不提供正确的scala-srchetype-simple,您需要自己键入正确的scala-srchetype。

It is like.

它像是。

 groupId:net.alchim31.maven

 artifactId:scala-archetype-simple

 version:1.6

 packaging:maven-archetype

#2


I had this issue as well and while trying to correct the ver number manually I found that simple using terminal or CMD you can just build a new project.

我也有这个问题,在尝试手动更正版本号时,我发现使用终端或CMD这么简单,你可以建立一个新项目。

Using the mvn commands ensures that your project is built with the correct ver.

使用mvn命令可确保使用正确的ver构建项目。

mvn -B archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app

mvn -B archetype:generate -DarchetypeGroupId = org.apache.maven.archetypes -DgroupId = com.mycompany.app -DartifactId = my-app

Reference: http://maven.apache.org/guides/getting-started/index.html

#1


Just make sure you use the up-to-date scala-archetype-simple, because IDEA requires new scala-archetype-simple to work with. But by default IDEA does not provide the correct scala-srchetype-simple to choose, you need to type in the right one by yourself.

只需确保使用最新的scala-archetype-simple,因为IDEA需要新的scala-archetype-simple才能使用。但默认情况下,IDEA不提供正确的scala-srchetype-simple,您需要自己键入正确的scala-srchetype。

It is like.

它像是。

 groupId:net.alchim31.maven

 artifactId:scala-archetype-simple

 version:1.6

 packaging:maven-archetype

#2


I had this issue as well and while trying to correct the ver number manually I found that simple using terminal or CMD you can just build a new project.

我也有这个问题,在尝试手动更正版本号时,我发现使用终端或CMD这么简单,你可以建立一个新项目。

Using the mvn commands ensures that your project is built with the correct ver.

使用mvn命令可确保使用正确的ver构建项目。

mvn -B archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app

mvn -B archetype:generate -DarchetypeGroupId = org.apache.maven.archetypes -DgroupId = com.mycompany.app -DartifactId = my-app

Reference: http://maven.apache.org/guides/getting-started/index.html