Gradle 格雷德尔:“我不知道;申请自";在脚本的其余部分之前进行求值?

Gradle 格雷德尔:“我不知道;申请自";在脚本的其余部分之前进行求值?,gradle,Gradle,我有一个包含多个组件/JAR的多项目脚本。 每个子脚本/项目定义组件标题: ext { componentTitle = 'Application1' } apply from: '../war/gradle/component.gradle' 共享代码位于component.gradle中: apply plugin: 'java' jar { manifest { attributes 'Implementation-Title': componentT

我有一个包含多个组件/JAR的多项目脚本。 每个子脚本/项目定义组件标题:

ext {
    componentTitle = 'Application1'
}

apply from: '../war/gradle/component.gradle'
共享代码位于component.gradle中:

apply plugin: 'java'

jar {
    manifest {
        attributes 'Implementation-Title': componentTitle    }
}
我得到一个错误:

评估脚本时出现问题

清单属性的值不能为null


这意味着在计算子脚本时不会定义componentTitle。componentTitle定义在“apply from”语句之前。

应用的脚本在
apply from:…
的位置得到精确的评估(通过添加一些
println
很容易确认)。一定还有别的问题。您可以尝试将
'Implementation-Title':componentTitle
替换为
'Implementation-Title':project.componentTitle
,尽管这不会有什么区别。

您是否确认路径正确并且Gradle正在查找component.Gradle?是的,Gradle正在查找component.Gradle。