Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename Gradle task

Tags:

gradle

I have the desire to "wrap" the tasks generated by one of Gradle's plugins while retaining the name of the task that the users interact with. It seems like the best way to do this would be to rename the task generated by the plugin and then create the wrapper task using the same name.

At first glance, TaskContainer#replace seemed like the way to go, except it just creates a new, empty task using the original name, while I already have the task object I want to put at that name.

How can I "rename" a Gradle task so that I can create a new task using the original name while preserving the original task?

like image 769
Chris Lieb Avatar asked Feb 25 '15 20:02

Chris Lieb


People also ask

How do I rename a file in Gradle?

Renaming files on copy The files used and generated by your builds sometimes don't have names that suit, in which case you want to rename those files as you copy them. Gradle allows you to do this as part of a copy specification using the rename() configuration.

What is task in Gradle?

The work that Gradle can do on a project is defined by one or more tasks. A task represents some atomic piece of work which a build performs. This might be compiling some classes, creating a JAR, generating Javadoc, or publishing some archives to a repository.

What is the Gradle build script file name?

We describe the tasks and projects by using a Groovy script. You can run a Gradle build using the Gradle command. This command looks for a file called build. gradle.

What is Gradle build file?

Android Studio uses Gradle, an advanced build toolkit, to automate and manage the build process, while allowing you to define flexible custom build configurations. Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of your app.


1 Answers

You could simply remove it from the task container while keeping a reference to it.

def oldTask = tasks.foo
tasks.remove(foo)
like image 189
Mark Vieira Avatar answered Oct 08 '22 12:10

Mark Vieira