0

I'm trying to get an argument from the command line using a Gradle task:

class myApk extends DefaultTask {

    @Option(option="apkName", description="apkName for your file")
    String apkName
    
    @TaskAction
    void uploadApk() {
        def arg = "curl -F \"demo${apkName}.apk=" +
                  "@${project.projectDir}\\app\\build\\outputs\\apk\\debug\\app-debug.apk\" " +
                  "https://URL"
        project.exec {
            commandLine("cmd", "/c", arg)
        }
    }
}
task uploadApk(type: myApk) { }

But after typing gradle uploadApk --apkName=foo in the terminal I get this kind of exception:

Problem configuring task :app:uploadApk from command line.
> Unknown command-line option '--apkName'.

P.S. I've read this topic(How to pass arguments from command line to gradle), but it doesn't seem helpful for this problem;(

3
  • 1
    use -PapkName=myvalue to pass gradle project parameters Commented Aug 25, 2020 at 17:57
  • Your example works fine for me. What version of Gradle do you use? Commented Aug 26, 2020 at 14:05
  • can we pass command line arguments to settings.gradle file? Commented May 23, 2021 at 18:43

1 Answer 1

1

Thanks to the comment above, I used -P to work it out

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.