Home - pford68/gradle-examples GitHub Wiki

Contents

Introduction

Gradle is a build tool that employs a DSL based on Groovy. The build file is written in code, instead of relying on configuration like Maven. These complex build operations can be scripted more easily. For some operations, Gradle's DSL provides methods or properties. In many cases, your file will use plain Groovy to get things done.

The behavior of Gradle can be configured to a large extent, either from the command line for single run, or from gradle.properties file within the project root, or a gradle.properties file in the $GRADLE_USER_HOME (which defaults to $HOME/.gradle).

Sample Gradle file

def sourceCompatibility = 1.5
def version = '1.0'

allprojects {
    apply plugin: 'java'
    apply plugin: 'cargo'
    apply plugin: 'cargo-base'
    apply plugin: 'war'

    repositories {
        mavenCentral()
    }
}

project(':services'){
    def spring_version = '3.1.1.RELEASE'

    dependencies {
        testCompile  group: 'junit', name:'junit', version: '4.11'
        testCompile  group: 'org.springframework', name:'spring-test', version: spring_version
        testCompile  group: 'org.codehaus.jackson', name:'jackson-mapper-asl', version: '1.8.5'
        compile group: 'org.slf4j', name:'slf4j-api', version: '1.6.1'
        compile group: 'ch.qos.logback', name:'logback-classic', version: '1.0.13'
        compile group: 'javax.inject', name:'javax.inject', version: '1'
        compile group: 'org.mongodb', name:'mongo-java-driver', version: '2.11.3'
        compile group: 'org.springframework', name:'spring-core', version: spring_version
        compile group: 'org.springframework', name:'spring-web', version: spring_version
        compile group: 'org.springframework', name:'spring-webmvc', version: spring_version
        compile group: 'org.jboss.resteasy', name:'resteasy-spring', version: '3.0.6.Final'
    }


    war {
        archiveName = 'aurora-services.war'
    }
}

project(':entanglement'){

    war {
        from 'src'
        archiveName = 'aurora-entanglement.war'
    }
}

project(':examples'){

    war {
        from 'src'
        archiveName = 'aurora-examples.war'
    }
}

project(':visualizations'){

    war {
        from 'src'
        archiveName = 'aurora-visualizations.war'
    }
}

project(':components'){

    war {
        from 'src'
        archiveName = 'aurora-components.war'
    }
}


buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'org.gradle.api.plugins:gradle-cargo-plugin:1.4'
    }
}

cargo {
    containerId = 'tomcat7x'

    deployable {
        file = file('/services/build/libs/aurora-services.war')
        context = 'aurora-services'
    }

    deployable {
       file = file('/entanglement/build/libs/aurora-entanglement.war')
       context = 'aurora-entanglement'
    }

    deployable {
       file = file('/visualizations/build/libs/aurora-visualizations.war')
       context = 'aurora-visualizations'
    }

    deployable {
       file = file('/examples/build/libs/aurora-examples.war')
       context = 'aurora-examples'
    }

    deployable {
        file = file('/examples/build/libs/aurora-components.war')
        context = 'aurora-components'
    }

    remote {
        hostname = 'localhost'
        username = 'tomcat'
        password = 'tomcat'
    }
}

Settings File

Example settings file

rootProject.name = 'aurora'
include 'services', 'visualizations', 'examples', 'entanglement', 'components'

It is a gradle file like any other.

  • Thus, it can use apply from.

    Example:

    apply from: new File(settingsDir, 'gradle/remoteHttpCacheSettings.gradle')
    
    • Note that the parameter to apply from here is a new File object.
    • This is different from the syntax in a build file.
  • It can invoke methods added to ext.