Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set task properties (or command line args) using Gradle Tooling API

I want to use the Gradle Tooling API to invoke Gradle from an Eclipse plugin through the Buildship plug-ins. I am able to run basic tasks without problems.

One of my use cases is to execute the gradle init task in a new project folder, but to work non-interactively I have to pass the --type command line argument (or set the type property) on the init task. I can't find any way in the tooling API to set the properties of a task or to pass a task-specific command line argument.

I have tried BuildLauncher.addArgument("--type", "plain") but this is interpreted as an argument to Gradle itself, which is invalid.

How can I pass the --type plain argument to the init task?

like image 907
Neil Bartlett Avatar asked Mar 16 '26 16:03

Neil Bartlett


1 Answers

After reading the docs here, I discovered you can set the task arguments via the Gradle command line build arguments. The important bit in the docs is:

Also, the task names configured by BuildLauncher.forTasks(String...) can be overridden if you happen to specify other tasks via the build arguments.

In my case I wanted to run gradle tasks --all via the tooling api. To get this working, I don't specify the task to run via forTasks(), I simply do not call that method. I set the task to run as part of the arguments via withArguments(). (In this case the arguments will be tasks --all).

I assume this should work the same for the init task.

like image 119
badsyntax Avatar answered Mar 18 '26 07:03

badsyntax



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!