Plugins 在配置阶段使用Gradle项目扩展属性
编写自定义Gradle插件时,如何在自定义插件的配置阶段访问消费Plugins 在配置阶段使用Gradle项目扩展属性,plugins,gradle,checkstyle,build.gradle,Plugins,Gradle,Checkstyle,Build.gradle,编写自定义Gradle插件时,如何在自定义插件的配置阶段访问消费build.Gradle中定义的扩展属性 请参阅以下MWE build.gradle apply plugin: 'codechecks' codechecks { checkstyleConfig = '/home/user/checkstyle.xml' } class CodechecksPlugin implements Plugin<Project> { void apply(Project pr
build.Gradle
中定义的扩展属性
请参阅以下MWE
build.gradle
apply plugin: 'codechecks'
codechecks {
checkstyleConfig = '/home/user/checkstyle.xml'
}
class CodechecksPlugin implements Plugin<Project> {
void apply(Project project) {
project.extensions.create('codechecks', CodechecksPluginExtension)
project.apply( [ plugin: 'checkstyle' ] )
project.checkstyle {
configFile = project.codechecks.checkstyleConfig
}
}
}
class CodechecksPluginExtension {
def checkstyleConfig = 'config/checkstyle/checkstyle.xml'
}
CodechecksPlugin.groovy
apply plugin: 'codechecks'
codechecks {
checkstyleConfig = '/home/user/checkstyle.xml'
}
class CodechecksPlugin implements Plugin<Project> {
void apply(Project project) {
project.extensions.create('codechecks', CodechecksPluginExtension)
project.apply( [ plugin: 'checkstyle' ] )
project.checkstyle {
configFile = project.codechecks.checkstyleConfig
}
}
}
class CodechecksPluginExtension {
def checkstyleConfig = 'config/checkstyle/checkstyle.xml'
}
想要的行为:checkstyle
插件使用build.gradle
codechecks
扩展中定义的配置文件
实际行为:由于尚未计算build.gradle
codechecks
扩展名,因此正在使用codechecks pluginextension
中的默认值
我已经尝试将插件中codechecks
扩展的所有用法放入闭包中,但由于在执行阶段出现类转换问题,它们无法正确扩展
谢谢你的帮助 project.afterEvaluate对我来说很有用。
尝试: