簡體   English   中英

在 IntelliJ 的 Maven 項目中運行 scala 代碼的 maven-scala-plugin 錯誤

[英]maven-scala-plugin error running scala code in a Maven project in IntelliJ

我正在嘗試使用 Maven 作為構建工具和 IntelliJ 作為我的 IDE 創建我的第一個“Hello World”Scala 項目。 運行mvn package時,我不斷收到以下錯誤。

Failed to execute goal org.scala-tools:maven-scala-plugin:2.15.2:compile

這是完整的錯誤:無法執行目標 org.scala-tools:maven-scala-plugin:2.15.2:compile (default) on project couchbase-test-3: wrap: org.apache.commons.exec.ExecuteException:進程因錯誤退出:1(退出值:1)

這是我的 pom.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>org.example</groupId>
  <artifactId>couchbase-test-3</artifactId>
  <version>1.0-SNAPSHOT</version>
  <inceptionYear>2008</inceptionYear>
  <properties>
    <scala.version>2.7.0</scala.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.4</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.specs</groupId>
      <artifactId>specs</artifactId>
      <version>1.2.5</version>
      <scope>test</scope>
    </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>
        <version>2.15.2</version>
        <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>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-eclipse-plugin</artifactId>
        <version>2.9</version>
        <configuration>
          <downloadSources>true</downloadSources>
          <buildcommands>
            <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
          </buildcommands>
          <additionalProjectnatures>
            <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
          </additionalProjectnatures>
          <classpathContainers>
            <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
            <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>
          </classpathContainers>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.scala-tools</groupId>
        <artifactId>maven-scala-plugin</artifactId>
        <version>2.15.2</version>
        <configuration>
          <scalaVersion>${scala.version}</scalaVersion>
        </configuration>
      </plugin>
    </plugins>
  </reporting>
</project>

我使用的 JDK 是 /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home。

我試圖運行的代碼只是打印出“Hello World:”:

package org.example

/**
 * Hello world!
 *
 */
object App extends Application {
  println( "Hello World!" )
}

任何想法如何解決這一問題?

我會嘗試再次從頭開始創建 Scala 項目,您可以按照此鏈接使用 Maven 構建一個簡單的 Scala 項目:

用Maven創建最基本的Scala項目?

Another option would be, when you are creating a Scala project with Maven you can choose an archetype for scala projects, and clean from the pom.xml what you don't need, that worked for me.

在此處輸入圖像描述

另一方面,您可以選擇 SBT 來創建 Scala 項目。 SBT is very easy and fully integrated with IntelliJ Idea, so you can create a SBT project in IntlliJ and make up the build.sbt file yourself and put in it the scala version you want, compile, package and execute with SBT.

舉個例子

name := "my_first_scala_app"

version := "0.1"

scalaVersion := "2.12.8"

libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.0-SNAP3" % Test

我希望這有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM