我没有找到在 Linux 中编译 scala 的好方法,所以我尝试了以下命令,
mkdir runnablescala
cd runnablescala
mkdir -p src/main/scala
mkdir -p src/main/resources
mkdir -p src/test/scala
mkdir -p src/test/resources
cd src/main/scala
mkdir -p com/johnathanmarksmith/gradle
vi com/johnathanmarksmith/gradle/HelloWorld.scala
package com.johnathanmarksmith.gradle;
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world!")
}
}
cd ../../..
vi build.gradle
apply plugin: 'scala'
jar {
baseName = 'smith'
version = '1.0'
manifest {
attributes 'Main-Class': 'com.johnathanmarksmith.gradle.HelloWorld' }
}
gradle build
构建失败并出现此结果
:compileJava UP-TO-DATE
:compileScala FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileScala'.
> 'compileScala.scalaClasspath' must not be empty
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
谁能告诉我如何编译scala?谢谢!我需要其他插件吗?
最佳答案
https://docs.gradle.org/current/userguide/scala_plugin.html :
Unless a task's scalaClasspath is configured explicitly, the Scala (base) plugin will try to infer it from the task's classpath. This is done as follows:
If a scala-library Jar is found on classpath, and the project has at least one repository declared, a corresponding scala-compiler repository dependency will be added to scalaClasspath.
Otherwise, execution of the task will fail with a message saying that scalaClasspath could not be inferred.
即您需要添加
dependencies {
compile 'org.scala-lang:scala-library:2.11.7'
}
到build.gradle
。如果你想构建一个独立的 jar,请参阅 Building a uberjar with Gradle 。
正如 Rex Kerr 提到的,如果您没有使用 Gradle 的具体原因,我会在 Scala 项目中使用 SBT。
关于scala - 如何将scala编译成可运行的jar文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33291506/