问题
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