Skip to content

Instantly share code, notes, and snippets.

@melix
Created May 29, 2013 14:53
Show Gist options
  • Save melix/5670897 to your computer and use it in GitHub Desktop.
Save melix/5670897 to your computer and use it in GitHub Desktop.
Apply local tweaks to a Gradle build if user.gradle is present
// here goes the conf
...
// append this
if (file('user.gradle').exists()) {
apply from: 'user.gradle' // if a user file is present, tweak the build (add tasks, ...). This file should not be in VCS.
}
@melix
Copy link
Author

melix commented May 29, 2013

The idea is to allow users to add tasks, shortcuts, ... to the Groovy build, without having to commit the changes to VCS.

@melix
Copy link
Author

melix commented May 29, 2013

My user.gradle would contain things like this, for example:

// Add desktop notifications
apply plugin: 'announce'

gradle.afterProject {project, projectState ->
    if (projectState.failure) {
        announce.announce ("Evaluation of $project FAILED\n${projectState.failure}", 'local')
    }
}

gradle.addBuildListener(
   ['buildStarted': {},
    'projectsEvaluated': {},
    'projectsLoaded': {},
    'settingsEvaluated': {},
    'buildFinished': { BuildResult result ->
    if (result.failure) {
       announce.announce("Build FAILED with ${result.failure}", 'local')
        } else {
       announce.announce("Build SUCCESSFUL", 'local')
        }
   }] as BuildListener
)

gradle.taskGraph.afterTask { Task task, TaskState state ->
    if (state.failure) {
        announce.announce ("Task $task FAILED\n${state.failure}", 'local')
    }
}

// fast local install
task fastInstall(dependsOn: install) {
   description='Installs a non indy version of Groovy into local Maven repo, without docs nor sources'
   allprojects {
    [javadoc,groovydoc,javadocAll,groovydocAll,sourceJar, groovydocJar, javadocJar]*.enabled = false
   }
   rootProject.ext.skipIndy = true
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment