Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extend existing Gradle task and override configuration

I'd like to define a new task called dbStatus that calls (or extends?) run, and just overrides the args property.

apply plugin: 'application'

run {
    args "server", "service.yml"
}


task(dbStatus, type: run) {
    args "db", "status", "service.yml
}

This doesn't work because "run" isn't a valid task class. Is there a quick way to extend a task and just override a property?

UPDATE: Resolution

Unfortunately I had to just define a brand new JavaExec task, and recreate the logic that run is configured to do. Here is what I came up with:

task(dbStatus, type: JavaExec) {
    main mainClassName
    classpath sourceSets.main.runtimeClasspath
    args "db", "status", "service.yml"
}

I don't think this is exactly the same as run, since it isn't running against the build jar I don't believe, but it works for my purposes.

like image 750
Sean Adkinson Avatar asked Jul 29 '14 23:07

Sean Adkinson


1 Answers

Tasks cannot be "extended" in this way. Instead, declare another task and configure it as appropriate. (It's common to configure multiple tasks at once to avoid code duplication.)

like image 110
Peter Niederwieser Avatar answered Sep 28 '22 10:09

Peter Niederwieser