Running scala REPL from gradle?

Is there a standard way to call scala REPL from a gradle task? Is there a plugin for this? I did not find him. I could follow this example, but it is a bit outdated, and I wanted to know if there is a better way:

http://gradle.1045684.n5.nabble.com/Reading-keyboard-input-td3073108.html

Thank.

+5
source share
2 answers

The Scala plugin bundled with Gradle does not currently support REPL. However, this may change soon as we are currently investing in improving our support for Scala. Let us know your wishes at http://forums.gradle.org .

+6
source

Scala REPL Gradle: Gradle REPL script.

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

.

+2

All Articles