How to get gradle property from command line?

我与影子孤独终老i 提交于 2020-07-10 08:43:07

问题


I am trying read a project property from command line interface. There is a task gradle properties, which prints all of them. Therefore, I can write: gradle properties | grep "rootProject: root project" | awk '{print $NF}' | tr -d "'" and get what I want. The returned result is correct. I would like to use a proper gradle command to achieve the same result. What is a gradle command to get the project name?

this is my build.gradle:

plugins {
    id 'java'
}

tasks.register("rootProjectName") {
    doLast {
        println(rootProject.name)
    }
}

build {
    println 'hi'
}

回答1:


Looks like you're just after the rootProject.name property. There is no built-in Gradle task that will give you that property. You can write a simple task that prints that value to the console which will simplify your command.

tasks.register("rootProjectName") {
    doLast {
        println(rootProject.name)
    }
}

Then simply call that task with -q:

$ ./gradlew rootProjectName -q
demo

You can see demo is simply printed out for this example.



来源:https://stackoverflow.com/questions/62581105/how-to-get-gradle-property-from-command-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!