How to provide argument to build task

How to provide argument to build task.

For instance, i want to download 60 build version from archiva to my local server path by providing ‘version’ argument 60 to build task.
could you please suggest how can i achieve this.

Example task:

task download(type: Download) {
src ‘http://archiva/repository/test/$version/project-$version.jar
dest new File(buildDir, ‘…/…/…/test/project.jar’)
username ‘username’
password ‘password’


gradle command:
gradle download version=60

I am using gradle-4.10.2 version.

The simplest way is to simply use a project property.

gradle download -ParchivaVersion=60

and in your task simply do

src "http://..../${archivaVersion}/projec-${archivaVersion}"

There is a more idiomatic way to do it where you could do something in a similar fashion like

gradle wrapper --gradle-version=5.0

for instance you could do

gradle download --archivaVersion=60

This does require a lot more code which for a simple task is not worth it.

1 Like

Thank you Schalk_Cronje for your kind reply.

I have used given archiva project property (archivaVersion)and it is working fine.
gradle download -ParchivaVersion=60
src “http://…/{archivaVersion}/projec-{archivaVersion}”

But problem is that i do not want to provide archivaVersion argument to other task. while executing other task it is failing due to unknown property error. Hence i am using my own property

Error while executing other task : gradle stop
Could not get unknown property ‘archivaVersion’ for task ‘:download’ of type

So i have used custom property(${project.findProperty(‘myProp’)}) and now this error is not coming for other tasks.
Am i doing correct way here?

You could provide a default value in

Then you wouldn’t necessarily need to provide the value on the command-line all the time.