我正在尝试创建我的第一个"Hello World“Scala项目,使用Maven作为构建工具,使用IntelliJ作为我的集成开发环境。在运行mvn package时,我一直收到以下错误。
Failed to execute goal org.scala-tools:maven-scala-plugin:2.15.2:compile下面是完整的错误:无法在项目couchbase- org.scala-tools:maven-scala-plugin:2.15.2:compile -3上执行目标测试(默认值):wrap: org.apache.commons.exec.ExecuteException: Process退出,返回错误: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!" )
}有什么办法解决这个问题吗?
发布于 2020-05-30 19:53:52
我会再次尝试从头开始创建Scala项目,您可以通过此链接使用Maven构建一个简单的Scala项目:
Creating the most basic Scala project with Maven?
另一种选择是,当你使用Maven创建Scala项目时,你可以为scala项目选择一个原型,然后从pom.xml中清除你不需要的东西,这对我很有效。

另一方面,您可以选择SBT来创建Scala项目。SBT非常简单,并且与IntelliJ Idea完全集成,所以你可以在IntlliJ中创建一个SBT项目,自己编写build.sbt文件并放入你想要的scala版本中,编译、打包并使用SBT执行。
举个例子
name := "my_first_scala_app"
version := "0.1"
scalaVersion := "2.12.8"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.0-SNAP3" % Test我希望这能帮到你。
https://stackoverflow.com/questions/62093099
复制相似问题