如何自动添加渐变依赖 [英] How to add gradle dependency automatically

查看:146
本文介绍了如何自动添加渐变依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有任何毕业生任务或任何其他的实用程序将添加依赖关系,例如

 依赖关系{
... //到目前为止依赖关系
compile'c​​om.new.dependency:xy
}
pre>

在您的 build.gradle 文件中,而不是手动输入。



我正在尝试写入IntelliJ插件,它会自动将库添加到任何项目中,到目前为止,我需要分析/解析文档内容,这很繁琐。



例如您可以在IntelliJ中进行项目设置,并添加库代码将自动添加。

解决方案

可以将集合指定为依赖关系,如:

 依赖关系{
compile ['org.slf4j:slf4j-api:1.7.5','org。 apache.com:commons-lang3:3.1']
}

这意味着你可以使用任何可以产生列表的东西您的插件维护一个文件,如:



compile.dependencies:

  org.slf4j:slf4j-api:1.7.5 
org.apache.commons:commons-lang3:3.1

然后,您可以将这些依赖项包含在项目中,如:

 依赖关系{
编译文件('compile.dependencies')readLines()
}

您的插件的用户必须知道将这些行添加到其build.gradle中。或者,更好的是,您可以将配置捆绑到包含文件中,如:

 子项目(){
依赖关系{
if(file('compile.dependencies')。exists()){
编译文件('compile.dependencies')readLines()
}

if(file('runtime.dependencies')。exists()){
运行时文件('runtime.dependencies')。readLines()
}
}
}

那么你的用户只需要使用apply from:来包含配置。


I'm wondering if there is any gradle task or any other util that will add dependency so e.g.

dependencies {
   ... // so far dependencies    
   compile 'com.new.dependency:x.y"
}

in your build.gradle file instead you manually type it.

I'm trying to write IntelliJ plugin that will automatically add a library to any project. So far I need to analyze/parse document content and it's tedious.

For example when you go to project setting in IntelliJ and add library the code is automatically added.

解决方案

You can specify collections as your dependencies, like:

dependencies {
   compile ['org.slf4j:slf4j-api:1.7.5','org.apache.commons:commons-lang3:3.1']
}

Which means you can use anything that can produce a list. If your plugin maintained a file like:

compile.dependencies:

org.slf4j:slf4j-api:1.7.5
org.apache.commons:commons-lang3:3.1

Then you could include the dependencies into the project like:

dependencies {   
    compile file('compile.dependencies').readLines()
}

Users of your plugin would have to know to add these lines to their build.gradle. Or, better, you could bundle the configuration into an include file, like:

subprojects() {
  dependencies {   
     if (file('compile.dependencies').exists()) {
       compile file('compile.dependencies').readLines()
     }

     if (file('runtime.dependencies').exists()) {
      runtime file('runtime.dependencies').readLines()
     }
  }
}

Then your users would only have to use "apply from:" to include the config.

这篇关于如何自动添加渐变依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆