-3

How to provide command line argument to build task?

For instance, I want to download 60 build version from an archive to my local server path. 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 download version=60

Dima Kozhevin
  • 3,602
  • 9
  • 39
  • 52
devops
  • 1
  • 4
  • 1
    Possible duplicate of [How to pass arguments from command line to gradle](https://stackoverflow.com/questions/11696521/how-to-pass-arguments-from-command-line-to-gradle) – madhead Dec 31 '18 at 23:31

1 Answers1

0

You can use Project Properties for this purpose (see Project Properties)

Example: consider the following task

task hello{
    doLast{
        println "Hello ${project.findProperty('myProp')}"
    }
}

You can pass property value as follows:

./gradlew hello -PmyProp=world

Note you should use another variable name than "version", as version is already a Gradle property attached to the project.

Note 2 : I noticed you are using simple quote for src value, this cannot work. You need to se double-quote for String interpolation ( see here ):

Use:

src "http://archiva/repository/test/$version/project-$version.jar"

instead of:

src 'http://archiva/repository/test/$version/project-$version.jar'
M.Ricciuti
  • 11,070
  • 2
  • 34
  • 54
  • Thank you for your response. At the first i have used project property archivaVersion and it worked. But problem is i do not want to provide argument to other task too. while executing other task it is failing due to unknown property error. Hence i am using my own property as you explained above.. – devops Jan 02 '19 at 11:30