首页 > 其他 > 详细

Groovy

时间:2019-08-11 15:49:56      阅读:85      评论:0      收藏:0      [点我收藏+]

Q&A

Gradle 中的 ext 究竟是什么?

gradle 中我们使用 ext 定义额外的各种属性,可是 ext 究竟是什么呢?

参看 ExtraPropertiesExtension - Gradle DSL,发现 ext 不是 Groovy 固有的定义,而是领域特定的语言(DSL)。使用方式是:

// 以下的 project 常常被省略
project.ext { foo = "bar" }

assert project.ext.get("foo") == "bar"
assert project.ext.foo == "bar"
assert project.ext["foo"] == "bar"

assert project.foo == "bar"
assert project["foo"] == "bar"

ext 实质上是一个内置的简单对象,但可以动态添加新属性,这个对象叫 ExtraPropertiesExtension,它内置在所有 ExtensionAware 中,ExtenstionAware 的已知子类有 ProjectSettingsTaskSourceSet,所以在这些类中可以直接使用所谓的 namespace method 动态新增新属性。

// Extensions are just plain objects, there is no interface/type
class MyExtension {
  String foo

  MyExtension(String foo) {
    this.foo = foo
  }
}

// Add new extensions via the extension container
project.extensions.create('custom', MyExtension, "bar")
//                       (?name?,   ?type?,       ?constructor args?, …)

// extensions appear as properties on the target object by the given name
assert project.custom instanceof MyExtension
assert project.custom.foo == "bar"

// also via a namespace method
project.custom {
  assert foo == "bar"
  foo = "other"
}
assert project.custom.foo == "other"

Gradle 依赖排除

dependencies {
    compile('com.zhyea:ar4j:1.0') {
        //excluding a particular transitive dependency:
        exclude module: 'cglib' //by artifact name
        exclude group: 'org.jmock' //by group
        exclude group: 'org.unwanted', module: 'iAmBuggy' //by both name and group
    }
}

参考

  1. Gradle 依赖排除

Groovy

原文:https://www.cnblogs.com/lshare/p/11334740.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!