[英]How to add gradle dependency automatically
我想知道是否有任何gradle任務或任何其他util將添加依賴項 ,例如
dependencies {
... // so far dependencies
compile 'com.new.dependency:x.y"
}
您可以在build.gradle文件中手動鍵入它。
我正在嘗試編寫IntelliJ插件,該插件會自動將庫添加到任何項目。 到目前為止,我需要分析/解析文檔內容,這很繁瑣。
例如,當您進入IntelliJ中的項目設置並添加庫時,代碼將自動添加。
您可以將集合指定為依賴項,例如:
dependencies {
compile ['org.slf4j:slf4j-api:1.7.5','org.apache.commons:commons-lang3:3.1']
}
這意味着您可以使用任何可以產生列表的東西。 如果您的插件維護如下文件:
compile.dependencies:
org.slf4j:slf4j-api:1.7.5
org.apache.commons:commons-lang3:3.1
然后,您可以將依賴項包含到項目中,例如:
dependencies {
compile file('compile.dependencies').readLines()
}
您插件的用戶必須知道將這些行添加到他們的build.gradle中。 或者,更好的是,您可以將配置捆綁到一個包含文件中,例如:
subprojects() {
dependencies {
if (file('compile.dependencies').exists()) {
compile file('compile.dependencies').readLines()
}
if (file('runtime.dependencies').exists()) {
runtime file('runtime.dependencies').readLines()
}
}
}
然后,您的用戶只需使用“ apply from:”(應用來自:)即可包含配置。
沒有這樣的工具,也沒有實用程序。 可以使用工具API向項目添加依賴項,但是引入的更改不會序列化到配置(build.gradle)文件中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.