gradle之jar包引用方式及排除依赖

一.加载jar包

  1. 从配置的仓库中引用jar包
    compile group: ‘dom4j’, name: ‘dom4j’, version: ‘1.6’
    简写为compile ‘dom4j:dom4j:1.6’
  2. 从本地仓库引用jar包
    compile file(‘libs/test.jar’)
    compile fileTree(dir:‘libs’,include:[’*.jar’])

二.排除依赖

  1. 排除单个jar包的依赖
    compile(‘displaytag:displaytag:1.1’) {
    exclude module: ‘itext’ //by artifact name
    exclude group: ‘commons-lang’ //by group
    exclude group: ‘commons-lang’, module: ‘commons-lang’
    //by both
    }
  2. 全局配置是在configuration中完成
    configurations {
    compile.exclude module: ‘commons-lang’
    all*.exclude group:‘commons-lang’, module: ‘commons-lang’
    }
  3. 禁止传递依赖
    compile(‘displaytag:displaytag:1.1’) {
    transitive = false
    }
    configurations.all {
    transitive = false
    }
  4. 强制使用某个版本
    compile(‘displaytag:displaytag:1.1’) {
    force = true
    }
    configurations.all {
    resolutionStrategy {
    force ‘displaytag:displaytag:1.1’
    }
    }
  5. 强制使用最新的依赖
    compile ‘displaytag:displaytag:+’

你可能感兴趣的:(gradle)