Override property in build.gradle from the command line

前端 未结 1 563
天涯浪人
天涯浪人 2021-02-02 06:35

In build.gradle we can define variables like:

def libVersion=\'someVersion\'

We can override properties in command line with

1条回答
  •  南方客
    南方客 (楼主)
    2021-02-02 07:13

    Here's an example:

    ext.greeting = project.hasProperty('greeting') ? project.getProperty('greeting') : 'hello'
    
    task greet << {
        println greeting
    }
    

    If you run gradle greet, it will print hello.

    If you run gradle -Pgreeting=welcome greet, it will print welcome.

    0 讨论(0)
提交回复
热议问题