Ramesh
Ramesh

Reputation: 851

Gradle command - can I use a file as command line arguments?

I would like to run a gradle task using a text file as command line arguments.

how can I do that in Windows and in Linux?

text file "run.txt" contains these arguments:

--tests com.tests.TestSpec.groovy -Denv=test

Tried running it in Windows machine as following and it did not work.

c:\MyProject\Tests>gradle < run.txt

Upvotes: 1

Views: 623

Answers (1)

Stanislav
Stanislav

Reputation: 28096

In Linux you can read a file content into a variable and use it as an argument as follows:

gradle "$(< run.txt)"

For Windows you can use something like this:

for /F "tokens=*" %x in (run.txt) do gradle %x

This is the Loop command example, which iterates over the run.txt file content, splitting it into the tokens and executing a gradle command over this tokens. tokens=* in this case means - process all tokens aon every line, by default it processes only the first token.

Buy IMHO, it's much easier to use a batch files or shell script for such a tasks. For example in Linux you can simply create a file named run.sh with the content:

gradle --tests com.tests.TestSpec.groovy -Denv=test

make this file executable

chmod +x ./run.sh

and just run it as follows

./run.sh

In Windows it's even easier, since you don't need to make a batch file executable.

Upvotes: 1

Related Questions