commandLine not working after upgrading to Gradle 5

Hi,
I upgraded my gradle version to 5.5.1 from 3.5.
Since .execute() got deprecated in gradle 5, i removed execute() in calling of task.

Here is my code.

def testExecTask = project.tasks.create(name: "test${testFile.name.capitalize()}" - '.uip', type: Exec) {
                    inputs.file testFile
                    inputs.files "${project.stage.testStageDir}"
                    commandLine ["${installShieldRoot}/sab/${installShieldExecutable}",
                                   "${testFile}".replaceAll('\\\\', '/'),
                                   "-pathVariable",
                                   "staging=${finalLocation}".replaceAll('\\\\', '/'),
                                   "-pathVariable",
                                   "staging64=${finalLocation}".replaceAll('\\\\', '/'),
                                   "-pathVariable",
                                   "ASSEMBLY_DIR=${project.buildDir}/build/kitting/assembly64".replaceAll('\\\\', /'),
                                   "-pathVariable",
                                   "images_dir=${project.stage.dir}/images".replaceAll('\\\\', '/'),
                                   "-build",
                                   "${configurationName}"]
                    environment KIT_OS_ARCH: "64"
                }
				
		testExecTask.execute()

Instead of testExecTask.execute(), now i am just calling task as testExecTask after upgrading to gradle 5.

Task is called but commandLine doesn’t get executed. Please can someone help as to how to make sure commandLine code is executed. Everything worked well in 3.5 gradle version.

Regards,
Anand

There is no way to “call” a task in Gradle.
The execute() method was an accident in the API that had many problems and thus was removed from the API.

If you really want to always run this command whenever the Gradle build is configured - which is most probably a pretty bad idea - then do not use a task of type Exec, but an exec { ... } closure. Configuration is the same as for the task.

Thanks for the response.
After using exec{ } instead of Type:Exec, I am getting below error.

> No signature of method: com.tim.gradle.plugins.kit.TestPlugin.exec() is applicable for argument types: (com.tim.gradle.plugins.kit.TestPlugin$_kitUipMethod_closure5) values: [com.tim.gradle.plugins.kit.TestPlugin$_kitUipMethod_closure5@270be080]
00:02:49.418 Possible solutions: grep(), every(), grep(java.lang.Object), every(groovy.lang.Closure), each(groovy.lang.Closure), use([Ljava.lang.Object;)

I assumed you are in a build script. But as you are in a plugin class, inject ExecOperations and call exec on that.

Thanks again for the response. ExecOperations was introduced in version 6, I am using version 5.5.1 of gradle.

Well, you should probably update instead of using an ancient version that was released more than 5 years ago. :smiley:
In the meantime use project.exec { ... }. :slight_smile:

@Vampire Thanks. It worked.

1 Like