Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to split/factor out common parts of Gradle build

We have several independent builds (each independent build is a multi-project build). The main build scripts become quite big as we have a set of common tasks reused by subprojects as well as there is a lot of repeation between indepedent builds. What we are looking for is:

  1. A way to split main build file into smaller files
  2. A way to reuse some parts of the build in other independent builds

What is the best way to achieve that in Gradle?

like image 272
Andrey Adamovich Avatar asked Apr 02 '10 12:04

Andrey Adamovich


People also ask

What is Buildscript in build Gradle file?

buildscript: This block is used to configure the repositories and dependencies for Gradle. dependencies: This block in buildscript is used to configure dependencies that the Gradle needs to build during the project.

Why are there multiple build Gradle files?

By default, the project-level Gradle file uses buildscript to define the Gradle repositories and dependencies. This allows different projects to use different Gradle versions.

What is multi-project build in Gradle?

A multi-project build in Gradle consists of one root project, and one or more subprojects. A basic multi-project build contains a root project and a single subproject. This is a structure of a multi-project build that contains a single subproject called app : Example 1. Basic multi-project build.


1 Answers

Gradle 0.9 allows you to import a build script from another build script. Have a look at: Configuring the project using an external build script. Basically it's apply from: 'other.gradle'.

One thing the user guide doesn't mention is that the 'from' parameter can be a URL, so you can make your shared scripts available via HTTP somewhere (eg your subversion repository), and import them from multiple builds.

like image 70
Adam Murdoch Avatar answered Oct 02 '22 20:10

Adam Murdoch