The TaskInternal.execute() method has been deprecated and is scheduled to be removed in Gradle 5.0

buildship
plugins

(Sanchez) #1

Hi All Experts,

During build, i am facing following error.
The TaskInternal.execute() method has been deprecated and is scheduled to be removed in Gradle 5.0.

Actually, it is caused from perform a ant unittests task .

project.task(‘run_unittests’, type: TestExecutionTask, group: BUILD_TEST_GROUP, description: “Runs the target ‘unittests’ with given test execution configuration”) { taskName ‘unittests’ }

I checked this project.task(string, closure) is not planned to be deprecated. In this case, how can i avoid the exception?


(Stefan Wolf) #2

Hi Jason,

I guess the task type TestExecutionTask is trying to use TaskInternal.execute for whatever task is configured. That is not supported any more.
I would be interested in the use case of the run_unittests task and the TestExecutionTask type in general. Why don’t you just run the task unittests directly from the command line?

Cheers,
Stefan


(Sanchez) #3

Hi Stefan,

We have a big project. Inside there are many steps for build. If we put everything inside build.gradle then this file will be too huge.

Then we developed groovy based plugins and apply them inside our build.gradle. The step ‘unittest’ is one of the many step in the plug in.

We also use gradle in jenkins for automatically build. Manually command is not possible with ci/cd.


(Stefan Wolf) #4

Hi Jason,

IIUC correctly then you want to have your build logic split into different plugins. That is perfectly fine. What I am saying is that the task run_unittests could be replaced by

task run_unittests {
    dependsOn 'unittests'
}

You see, no custom task type, no call to TaskInternal.execute. If you want to have a task which depends on a group of tasks (even from sub-projects) or add some dependencies from a plugin that is also not a problem.
I understand that, when running on Jenkins, you invoke Gradle. I guess you will invoke some tasks from Gradle (that is the point), and these should depend on whatever tasks you want to run. So there is still no need to use TaskInternal.execute.
Am I missing something?

Cheers,
Stefan


(Sanchez) #5

Hi Stefan

thanks for your fast reply.

Could this be used inside groovy? i know from gradle it works. I have many other logic located in groovy plugin.


(Stefan Wolf) #6

Yes, dependsOn can be used from a plugin (written in Groovy, Kotlin or Java) without any problems.


(Sanchez) #7

may u let me know the whole name? for example org.gradle.api.**


(Sanchez) #8

Or you mean, I set my task depends on another task with method setDependsOn(antTaskNames)?


(Stefan Wolf) #9

Yeah. I would suggest you use Task.dependsOn instead of setDependsOn, so you would actually add to the dependencies instead of overwriting them.


(Sanchez) #10

Hi Stefan,

Confused. Task.dependson is in gradle context. But i am talking in groovy code. I need set the dependency inside groovy code. Otherwise i need refactor too much.


(Stefan Wolf) #11

I don’t understand what kind of Groovy code you are talking about? Where does your Groovy code life and how do you apply it to your build script? Could you give me a self contained example?


(Sanchez) #12

Hi Stefan,

I have groovy based plugin. Then with 'apply plugin ‘groovy plugin name’, i include it in build.gradle file.

in side groovy code , i have following code which cause exception now.And now i have to change this code to let it be able to executed.

project.task(‘run_unittests’, type: TestExecutionTask, group: BUILD_TEST_GROUP, description: “Runs the target ‘unittests’ with given test execution configuration”) { taskName ‘unittests’ }


(Stefan Wolf) #13

Replace the code by

project.task('run_unittests', group: BUILD_TEST_GROUP, description: "Runs the target ‘unittests’ with given test execution configuration") {
    dependsOn 'unittests'
}

Doesn’t that work? What is ‘unittests’? The name of another task?


(Sanchez) #14

yes. It is the ant’s task name.


(Stefan Wolf) #15

I guess you are importing the ant build into Gradle.
Does my above suggestion work? Does your custom code now work?
There shouldn’t be any difference when calling methods an TaskInternal from a build script or from a Groovy class when developing a plugin. The dependsOn method should still be present.


(Sanchez) #16

Hi Stefan,

i believe your way should work. Currently, i am working on other topic. afterwards, i will try to fix the issue with dependsOn .Thanks.