Source From Here
Question
How can I set a global variable that can be accessed from build.gradle and tasks?
How-To
To set a global variable by ExtraPropertiesExtension:
To access it from anywhere in the project:
For instance:
- builld.gradle
Execution output:
Question
How can I set a global variable that can be accessed from build.gradle and tasks?
How-To
To set a global variable by ExtraPropertiesExtension:
- project.ext.set("variableName", value)
- project.variableName
- builld.gradle
- /* 引用 java plugin 獲得編譯 java 專案相關的 task $ */
- apply plugin: 'java'
- /* 引用 application plugin 獲得執行 java 專案相關的 task $ */
- apply plugin:'application'
- printf("project.ext=%s\n", project.ext)
- project.ext["name"] = "john"
- task hello(type: GreetingTask)
- class GreetingTask extends DefaultTask{
- @TaskAction
- def greet()
- {
- printf('Hello from GreetingTask %s', project.ext.name)
- }
- }
- printf("Read project.name='%s'\n", project.ext.name)
This message was edited 4 times. Last update was at 25/06/2017 14:59:44
沒有留言:
張貼留言