How To Set Up Scala Projects With Gradle For Eclipse

Do you like this?

Summary:
This short example shows you the steps to set up Scala projects for Eclipse using Gradle build tool.


Content:

Please make sure you have got scala and gradle set up before proceeding. In this example, we are going to create a hello world application using scala and gradle.
1) mkdir helloworld
2) cd helloworld
3) create a file build.gradle

apply plugin: 'scala'
apply plugin: 'eclipse'

repositories{
    mavenCentral()
    mavenLocal()
}

dependencies{
    compile 'org.slf4j:slf4j-api:1.7.5'
    compile "org.scala-lang:scala-library:2.11.2"
    testCompile "junit:junit:4.11"
}

task run(type: JavaExec, dependsOn: classes) {
    main = 'Main'
    classpath sourceSets.main.runtimeClasspath
    classpath configurations.runtime
}
4) in the folder helloworld, run the following commands
gradle eclipse
5) Import the project to eclipse
6) Every time you add new dependencies, remember to run gradle eclipse so that the libraries references in eclipse settings are updated accordingly.
7) Under the folder src/main/scala, create a file Main.scala
object Main extends App {
	println("Hello World");
}
8) In the folder helloworld, run the following commands
gradle run

 
comments powered by Disqus