gpt4 book ai didi

scala - 如何将Scala编译为可运行的jar文件

转载 作者:行者123 更新时间:2023-12-03 04:48:54 24 4
gpt4 key购买 nike

我没有找到在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的特定理由,我将选择SBT来进行Scala项目。

关于scala - 如何将Scala编译为可运行的jar文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33291506/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com