How to use gradle properties in build.gradle

前端 未结 3 1363
陌清茗
陌清茗 2021-02-03 21:46

When I run this task:

task tmpTask << {
    project.properties.each {println \"   $it\"}
}

I see:

org.gradle.java.home=/u         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-03 21:57

    From gradle.properties

    Add prop to the file gradle.properties

    hi1=hi
    

    From CommandLine

    Add -Pxxx end of commandline.

    ./gradlew -q readPropertiesTask -Phi2=tete
    

    Several properties:

    ./gradlew -q readPropertiesTask -Phi2=tete -Phi3=rr
    

    How to read?

    val propFromFile = project.properties["hi1"]
    println("propFromFile = $propFromFile")
    

提交回复
热议问题