Extend existing Gradle configuration and override configuration

I would like to define a new task called dbStatus that calls (or extends?) run and simply overrides the args property.

 apply plugin: 'application' run { args "server", "service.yml" } task(dbStatus, type: run) { args "db", "status", "service.yml } 

This does not work because "run" not a valid task class. Is there a quick way to expand a task and simply override a property?

UPDATE: permission

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

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

I do not think this is exactly the same as run , since it does not work against the jar assembly, I do not believe it, but it works for my purposes.

+6
source share
1 answer

Tasks cannot be β€œexpanded” in this way. Instead, declare another task and configure it accordingly. (Usually for setting up multiple tasks at once to avoid code duplication.)

+4
source

Source: https://habr.com/ru/post/973072/


All Articles