Questions And Answers

More Tutorials

Scala Working With Gradle


Basic Setup

1.Create a file named SCALA_PROJECT/build.gradle with these contents:

group 'scala_gradle'
version '1.0-SNAPSHOT'
apply plugin: 'scala'
repositories {
 maven {
 url ""
dependencies {
 compile group: 'org.scala-lang', name: 'scala-library', version: '2.10.6'
task "create-dirs" << {
 sourceSets*.scala.srcDirs*.each { it.mkdirs() }
 sourceSets*.resources.srcDirs*.each { it.mkdirs() }

2. Run gradle tasks to see available tasks.

3. Run gradle create-dirs to create a src/scala, src/resources directory.

4. Run gradle build to build the project and download dependencies.

Create your own Gradle Scala plugin

After going through the Basic Setup example, you may find yourself repeating most part of it in every single Scala Gradle project. Smells like boilerplate code...

What if, instead of applying the Scala plugin offered by Gradle, you could apply your own Scala plugin, which would be responsible for handling all your common build logic, extending, at the same time, the already existing plugin.

This example is going to transform the previous build logic into a reusable Gradle plugin.

Luckyly, in Gradle, you can easily write custom plugins with the help of the Gradle API, as outlined in the documentation. As language of implementation, you can use Scala itself or even Java.


In this page (written and validated by ) you learned about Scala Working With Gradle . What's Next? If you are interested in completing Scala tutorial, your next topic will be learning about: Scala XML Handling.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.