如何在交换内部库依赖项时在Gradle中添加对jar的依赖性

时间:2015-10-06 14:37:22

标签: gradle android-gradle

我正在尝试将jar依赖项添加到我的Android项目中:

dependencies {
  compile files('<SOME_JAR>')
}

但jar包装了一个我不想包含的库依赖。相反,我想声明一个更新版本的库:

dependencies {
  compile '<NEW_VERSION_LIBRARY>'
  compile files('<SOME_JAR>') {
    exclude '<OLD_VERSION_LIBRARY>'
  }
}

是否有可能在Gradle中实现这样的目标?

1 个答案:

答案 0 :(得分:1)

如果您的依赖项正在加载给定库的多个版本,并且您想要使用特定版本,那么您可以执行类似这样的操作,它将始终使用Groovy 2.4.5:

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.group == 'org.codehaus.groovy') {
            details.useVersion '2.4.5'
        }
    }
}

如果您只是想避免加载特定的依赖项,因为您更喜欢使用其他东西,那么您需要这样的东西,这将排除Apache Commons Logging并替代SLF4J和Logback:

dependencies {
    compile ( "com.orientechnologies:orientdb-graphdb:2.0.7" ) { 
        exclude module:'commons-logging' 
    }
    compile 'org.slf4j:slf4j-api:1.7.12' 
    runtime 'org.slf4j:jcl-over-slf4j:1.7.12' 
    runtime 'ch.qos.logback:logback-classic:1.1.3'
}
相关问题