Gradle snippets: Modularize your scripts

Build files tend to grow in time. New tasks are added, some customizations are made and you end up with several pages of groovy code. Gradle is based on Groovy, so many constructs can be really simplified, but often it’s not enough. That’s where Gradle comes in. You can split your build files into logical pieces:

// in build.gradle
apply from: "libraries.gradle"
apply from: "subprojectsTasks.gradle"
// in libraries.gradle
versions = [
  abc: "1.6"
]

libraries = [
  abc: "org.abc:abc:${versions.abc}"
]
// in subprojetsTasks.gradle
subprojects {
  apply plugin:"java"

  dependencies {
    compile libraries.abc
  }
}

And that’s it. You can safely split your build file into logical parts.

Tagged with: , ,
Posted in gradle snippets

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>