// Fetching Spring Core 3.0.6 without any of its dependencies dependencies { compile('org.springframework:spring-core:3.0.6') { transitive = false } }
1 2 3 4 5 6
// Forcing Spring Core 3.0.6 to dominate any other versions of Spring Core in the dependency graph dependencies { compile('org.springframework:spring-core:3.0.6.RELEASE') { force = true } }
1 2 3 4 5 6
Avoiding commons-logging as a transitive dependency of Spring Core dependencies { compile('org.springframework:spring-core:3.0.6.RELEASE') { exclude name: 'commons-logging' } }
File dependency
1 2 3 4
// Declaring a dependency explicitly on a locally managed module dependencies { compile files('lib/hacked-vendor-module.jar') }
1 2 3 4
// Depending recursively on all of the files under lib dependencies { compile fileTree('lib') }
In some cases, we might want to obtain POMs from one website (say, a centralized corporate repo), but download build artifacts from a mirrored copy of the repo somewhere else in the network.主要目的是节省带宽,提高下载速度。
1 2 3 4 5 6 7 8 9 10
// Setting the artifact URL as distinct from the default POM URL repositories { // Overriding artifacts for an internal repo maven { url = 'http://central.megacorp.com/main/repo' artifactUrls = [ 'http://dept.megacorp.com/local/repo' ] } // Obtain Maven Central artifacts locally mavenCentral artifactUrls: ['http://dept.megacorp.com/maven/central'] }
配置 Resolution Strategy
1 2 3 4 5 6
// Failing the build when a dependency version conflict is detected configurations.all { resolutionStrategy { failOnVersionConflict() } }
1 2 3 4 5 6
// Forcing a particular version of a given dependency configurations.all { resolutionStrategy { force 'commons-collections:commons-collections:2.1' } }