Sample Gradle Tasks and Notes

didn’t appreciate this post when first wriiten, but means a lot more now – enjoy 😀

Life in the I.T. Fast Lane

www.gradleware.com
Well worth a look-see for more Gradle inspiration: http://evgeny-goldin.com/wiki/Gradle

Sample Gradle Zip Task

task zip(type: Zip) {
    from jar.outputs.files
    from('scripts/') {
      fileMode = 0755
      include '**/*.sh'
      include '**/*.bat'
    }
    from('lib/') {
        include '**/*.jar'
        into('lib')
    }
    from('.') {
        include 'project.config'
    }
}

Custom Task Types

extend DefaultTask

Actions:

@org.gradle.api.tasks.TaskAction
class FtpTask extends DefaultTask 
{
    String host = 'docs.mycompany.com'
    @TaskAction
    def ftp() {
        println host
        // do something complicated
    }
}

OR

class FtpTask extends DefaultTask {
    String host = 'docs.mycompany.com'
    String user
    String password

    @TaskAction
    def ftp() { println host }
}

task dosomething( type: FtpTask, dependsOn: ... ) {
    user     = '...'
    password = '...'
}

List Method Pointers and DSL

Groovy provides a way to have a reference to an object’s method :

What a great way to create your own DSL !

def shoppingList = []
def add = shoppingList.&add
def remove = shoppingList.&remove…

View original post 674 more words

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s