Gradle:我如何委托父项目的resolutionStrategy?

时间:2018-01-30 02:28:31

标签: gradle dependency-management

我有一个定义resolutionStrategy的Gradle父项目。我想覆盖eachDependency对某些依赖项的行为,但委托给其他依赖项。我怎样才能做到这一点?我怎样才能获得对父母的ResolutionStrategy的引用,以便我可以委派?

configurations.all {
  resolutionStrategy {
    eachDependency { DependencyResolveDetails details ->
      // how can I delegate to the parent here?
    }
  } 
}

1 个答案:

答案 0 :(得分:0)

看起来您可以执行多项eachDependency操作,因此对于我的问题,父级eachDependency已经运行,但我可以覆盖它在孩子身上所做的任何事情eachDependency

编辑:根据要求。在我的情况下,父母将杰克逊设置为不同的版本。这就是我强迫它进入孩子build.gradle中的特定版本的方式:

def jacksonGroups = [
        'com.fasterxml.jackson.core',
        'com.fasterxml.jackson.dataformat',
        'com.fasterxml.jackson.datatype',
        'com.fasterxml.jackson.module'
] as Set

configurations.all {
  resolutionStrategy {
    eachDependency { DependencyResolveDetails details ->
      if (jacksonGroups.contains(details.requested.group)) {
        details.useVersion '2.9.2'
      }
    }
  }
}