在插件中获得奇怪的关闭错误

时间:2016-10-27 00:04:31

标签: gradle

我无法理解为什么我会通过这个插件获得关闭错误。拿这个申请:

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。

1 个答案:

答案 0 :(得分:0)

project_hash 是一个变量,因此您必须直接指定值:

metadata {
    project_hash = '123123123'
}

您目前正在使用此功能(例如 project_hash('xyz')),这在那里不适用