gpt4 book ai didi

gradle - gradle 外部构建文件应该放在哪里?

转载 作者:行者123 更新时间:2023-12-03 03:43:39 25 4
gpt4 key购买 nike

我想将外部文件导入到我的 build.gradle 例如

apply from 'other.gradle' 

它只会在当前目录中查找文件吗?

您如何为外部构建文件设置一个众所周知的地方?将 other.gradle 的完整路径放在 build.gradle 中,例如
apply from '///C:/Users/me/.gradle/other.gradle' 

但是不同操作系统上的用户可能有不同的路径。

我尝试在 gradle.properties 中添加一个属性并在 build.gradle 中使用它,但它不起作用:
local_build_system="///C:/Users/me/.gradle"

apply from: '${local_build_system}/other.gradle'

我得到以下输出:
* What went wrong:
A problem occurred evaluating root project 'helloworld'.
> Could not read script 'C:\Users\me\workspace\helloworld\${local_build_system}\other.gradle' as it does not exist.

我假设在执行“应用”时该属性没有被解析,因为可以从任务中打印出该属性就好了
println "local_build_system ${local_build_system}"

编辑添加:

我尝试这样做的原因是阅读用户指南(第 59 章 http://www.gradle.org/docs/current/userguide/organizing_build_logic.html),其中显示“共享脚本。在外部构建中定义通用配置,并将脚本应用于多个项目,可能跨越不同的构建。”

最佳答案

相对路径是相对于构建脚本的。按照惯例,脚本插件进入 $rootDir/gradle ,这意味着它们可以与 apply from: "$rootDir/gradle/someScript.gradle" 一起应用.脚本插件通常存储在项目的源存储库中,并且不会在构建之间共享(除非多个构建共享同一个源存储库)。正如 Radim 已经说过的,字符串插值仅支持双引号字符串文字。

关于gradle - gradle 外部构建文件应该放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23936161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com