Gradle : How to import a gradle file in another gradle file

How to Import Gradle file in another gradle file.

To import a gradle file in a gradle file you can use the following command in .gradle.

We have a gradle file build.gradle and we are including two other gradle files tasks.gradle and test.gradle.

apply from : 'tasks.gradle'
apply from : 'https://ekiras.github.io/temp/test.gradle'

Here, in line 1, we have imported tasks.gradle which lies in the same directory as build.gradle and in line 2 we have imported a test.gradle from a remote server. (Git hub pages in this case, it can be an s3 url or your server file url)

Test Imported gradle file task

build.gradle has the following content

group 'com.ekiras'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply from : 'tasks.gradle'
apply from : 'https://ekiras.github.io/temp/test.gradle'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

tasks.gradle has the following contents

task hello{
    println "Hello World"
}

We can now run the task hello with the following command

gradle -q hello

It will give the following output.

Hello World

No comments :

Post a Comment