How to use gradle properties in build.gradle

前端 未结 3 1398
陌清茗
陌清茗 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 22:08

    For anyone else's benefit. If the property you define is not dot separated, then you can simply refer to it directly.

    In your gradle.properties:

    myProperty=This is my direct property
    my.property=This is my dotted property with\t\t tabs \n and newlines
    

    In your build.gradle:

    // this works
    println myProperty
    println project.property('my.property')
    
    // this will not
    println my.property
    

提交回复
热议问题