Is it possible to update config of task (type: Exec) after configuration phase?

Hello everyone, I have a task of type: Exec, which has to be configured with PASSWORD.

project.task('undeployWebserviceApp', type: Exec) {
 args = [... '-password', rootProject.wasPassword, ...]
 executable = pathToWsadmin
 doLast {

This password need to be inserted in runtime:

task credentialsWasInput {
 if (project in [project(':profile_management')]) {
         def wasPassword = System.console()
                     .readPassword("\nPlease enter password for WS AS user ${wasLogin}: ").toString()
         project.ext["wasPassword"] = wasPassword

But not all tasks need to input the password! So, as i can see, i have to complete configuration of Exec task only in configuration phase with already known password (which will be available only in second phase). And in conf. phase it’s not possible to use taskGraph… How to avoid this?

Best regards, ILIA

I think you could do it with the taskGraph. You’d check if one of the password requiring tasks was in the task graph. If it is, you’d prompt for a password and then configure the password requiring tasks some more (to add the password args). See the answer here for some clues:

Another way to do it would be to create a custom task class. The task’s action can just call project.exec {}, but you can prompt for the password just before you exec that way. This would be OK if you were talking about one task.

1 Like