Gradle: "apply from"在脚本的其余部分之前被评估?

标签 gradle

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

ext {
    componentTitle = 'Application1'
}

apply from: '../war/gradle/component.gradle'

共享代码在component.gradle中:

apply plugin: 'java'

jar {
    manifest {
        attributes 'Implementation-Title': componentTitle    }
}

我收到错误:

评估脚本时出现问题。

The value of a manifest attribute must not be null.

这意味着在评估子脚本时尚未定义 componentTitle。 componentTitle 定义位于“apply from”语句之前。

最佳答案

应用的脚本在 apply from: ... 处准确评估(通过添加一些 println 即可轻松确认)。一定还有其他问题。您可以尝试的一件事是将 'Implementation-Title': componentTitle 替换为 'Implementation-Title': project.componentTitle,尽管它应该没有什么区别。

关于Gradle: "apply from"在脚本的其余部分之前被评估?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20764748/

相关文章:

java - Spring Boot-摆脱Hikari数据源并使用H2

java - 在 Intellij IDEA 中用 build.gradle 替换 Build Artifact

groovy - gradle build.gradle 依赖项 - oracle 驱动程序?

java - gradlew assemble 在 Travis-CI 上失败

Android 构建工具阻止 ProGuard 删除未使用的 appcompat 库类

java - CircleCI + Gradle + Heroku 部署

spring - 使用Gradle下载Spring 4源

android - 运行flutter项目时如何修复 "Finished with error: Gradle task assembleDebug failed with exit code -1"错误

java - AnysoftKeyboard (Android) 的构建问题

gradle - 无法使用无效的网址解析Gradle依赖项的 'spring-boot-starter-request-jpa'