如何将scala编译为runnable jar文件

时间:2015-10-22 22:00:51

标签: scala gradle

我没有找到在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?谢谢!我还需要其他任何插件吗?

1 个答案:

答案 0 :(得分:3)

https://docs.gradle.org/current/userguide/scala_plugin.html

  

除非显式配置任务的scalaClasspath,否则Scala(base)插件将尝试从任务的类路径中推断出它。这样做如下:

     

如果在类路径上找到了scala-library Jar,并且该项目至少声明了一个存储库,则会在scalaClasspath中添加相应的scala-compiler存储库依赖项。

     

否则,执行任务将失败,并显示一条消息,指出无法推断出scalaClasspath。

即。你需要添加

dependencies {
  compile 'org.scala-lang:scala-library:2.11.7'
}

build.gradle。如果您想构建一个独立的jar,请参阅Building a uberjar with Gradle

正如Rex Kerr所提到的,如果您没有特定的理由使用Gradle,我会选择SBT参与Scala项目。

相关问题