DependencyConstraintHandler 用于声明依赖约束。
支持多种依赖约束表示法。下面将对此进行描述。对于通过这种方式声明的每个依赖约束,都会创建一个 DependencyConstraint 对象。您可以使用此对象查询或进一步配置依赖约束。
您也可以直接添加 DependencyConstraint 的实例
configurationName(<instance>)
依赖约束也可以通过提供任何其他受支持的依赖约束表示法的 Provider 来声明。
支持两种声明外部模块依赖约束的表示法。一种是按以下格式的字符串表示法
configurationName("group:name:version")
另一种是映射表示法
configurationName(group: group, name: name, version: version)
在这两种表示法中,除名称以外的所有属性都是可选的。
plugins {
id("java-library") // so that we can use 'implementation', 'testImplementation' for dependency constraints
}
dependencies {
constraints {
//for dependencies found in artifact repositories you can use
//the string notation, e.g. group:name:version
implementation 'commons-lang:commons-lang:2.6'
testImplementation 'org.mockito:mockito:1.9.0-rc1'
//map notation:
implementation group: 'com.google.code.guice', name: 'guice', version: '1.0'
}
}
| 方法 | 描述 |
add(configurationName, dependencyNotation) | 向给定配置添加依赖约束。 |
add(configurationName, dependencyNotation, configureAction) | 向给定配置添加依赖约束,并使用给定闭包配置依赖约束。 |
create(dependencyConstraintNotation) | 创建依赖约束而不将其添加到配置中。 |
create(dependencyConstraintNotation, configureAction) | 创建依赖约束而不将其添加到配置中,并使用给定闭包配置依赖约束。 |
enforcedPlatform(notation) | 声明对强制平台的约束。如果目标坐标表示多个潜在组件,则将选择平台组件,而不是库。强制平台是一个其直接依赖项被强制的平台,这意味着它们将覆盖图中找到的任何其他版本。 |
enforcedPlatform(notation, configureAction) | 声明对强制平台的约束。如果目标坐标表示多个潜在组件,则将选择平台组件,而不是库。强制平台是一个其直接依赖项被强制的平台,这意味着它们将覆盖图中找到的任何其他版本。 |
DependencyConstraint add(String configurationName, Object dependencyNotation)
向给定配置添加依赖约束。
DependencyConstraint add(String configurationName, Object dependencyNotation, Action<? super DependencyConstraint> configureAction)
Action<? super DependencyConstraint>向给定配置添加依赖约束,并使用给定闭包配置依赖约束。
DependencyConstraint create(Object dependencyConstraintNotation)
创建依赖约束而不将其添加到配置中。
DependencyConstraint create(Object dependencyConstraintNotation, Action<? super DependencyConstraint> configureAction)
Action<? super DependencyConstraint>创建依赖约束而不将其添加到配置中,并使用给定闭包配置依赖约束。
DependencyConstraint enforcedPlatform(Object notation)
声明对强制平台的约束。如果目标坐标表示多个潜在组件,则将选择平台组件,而不是库。强制平台是一个其直接依赖项被强制的平台,这意味着它们将覆盖图中找到的任何其他版本。
DependencyConstraint enforcedPlatform(Object notation, Action<? super DependencyConstraint> configureAction)
Action<? super DependencyConstraint>声明对强制平台的约束。如果目标坐标表示多个潜在组件,则将选择平台组件,而不是库。强制平台是一个其直接依赖项被强制的平台,这意味着它们将覆盖图中找到的任何其他版本。