从Gradle中运行Scala REPL?

5
2个回答

6

目前Gradle捆绑的Scala插件不支持REPL。但是,我们正在投资改进Scala支持,这可能很快会有所改变。请在http://forums.gradle.org告诉我们您的愿望。


感谢您的快速回复。已完成:http://forums.gradle.org/gradle/topics/running_the_scala_repl_from_gradle。 - Julio Garcia

2
以下是关于如何启动Gradle项目的Scala REPL的一种方法:让Gradle编译和输出类路径,然后通过一个shell脚本单独启动REPL。请参考以下内容:

build.gradle

project(':repl') {

    def scalaVersion = '2.11.7'

    // Require the scala-compiler jar
    buildscript {
        dependencies {
            classpath "org.scala-lang:scala-compiler:${scalaVersion}"
        }
        repositories {
            mavenCentral()
        }
    }

    // The path of the scala-compiler jar
    def scalaPath = buildscript.configurations.classpath.find {
        it.name == "scala-compiler-${scalaVersion}.jar"
    }

    // The classpath of this project and its dependencies
    def classpath = sourceSets.main.runtimeClasspath.asPath

    // Prints the classpath needed to launch the REPL
    task printClasspath << {
        println "${scalaPath}:${classpath}"
    }

}

repl.sh

#!/bin/bash
gradle :repl:compileScala && \
java -Dscala.usejavacp=true \
     -classpath "$(gradle :repl:printClasspath --quiet)" \
     scala.tools.nsc.MainGenericRunner

更多详细信息请查看我的博客文章


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接