我不明白为什么我通过这个插件收到关闭错误。对此申请:
class MetadataPlugin implements Plugin<Project> {
Project project
MetadataExtension extension
static final METADATA_REPORT = 'metadataReport'
static final METADATA_REPORT_TASK = ':' + METADATA_REPORT
@Override
void apply(Project project) {
this.project = project
// Create and install the extension object
extension = project.extensions.create('metadata', MetadataExtension)
// *** create the tasks ***
def ignore = project.tasks.create(METADATA_REPORT, MetadataReportTask)
ignore.group = PLUGIN_GROUP
ignore.description = 'Gets the detailed information for this project and formats it into a user readable report'
// *** validate the build file ***
project.afterEvaluate {
def String ext_hash = project.extensions.metadata.project_hash
def String hash = {
if (ext_hash == null) {
throw new InvalidUserDataException(
"You must configure the metadata:project_hash value before running any form of build"
)
}
return ext_hash
}
throw new InvalidUserDataException(hash)
}
}
}
添加到它这个build.gradle
plugins {
id 'metadata'
}
metadata {
project_hash '123123123'
}
并产生此错误。
19:44:49.934 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
19:44:49.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
19:44:49.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
19:44:49.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] A problem occurred configuring root project 'junit9025097301225311002'.
19:44:49.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > com.devops.gradle.metadata.MetadataPlugin$_apply_closure1$_closure2@5bff38f7
19:44:49.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
我不明白为什么错误不是123123123,为什么它会给我应用闭包错误?扩展名不过是一个简单的pojo。
最佳答案
project_hash是变量,因此您必须直接分配值:
metadata {
project_hash = '123123123'
}
您当前正在使用此功能(例如 project_hash('xyz'))在此处不适用
关于gradle - 插件中出现奇怪的关闭错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40274050/