2012-03-31 72 views

回答

6

与Gradle捆绑在一起的Scala插件目前没有REPL支持。然而,这可能会很快改变,因为我们目前正在投资改善我们的Scala支持。让我们在http://forums.gradle.org处了解您的愿望。

+0

完成:http://forums.gradle.org/gradle/topics/running_the_scala_repl_from_gradle。感谢您的及时回应。 – 2012-04-01 00:50:57

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我blog post

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

更多细节。