gradle third party Jar package dependencies unified management

1. Background

Gradle of a project often contain a lot of sub-projects, each project has its own sub-Jar package dependencies. The reality is that each sub-project of introducing jar package are casual, version number, variety, how unified version numbers for each sub-project? Unified management of third-party reliance?
After the version number of unification, if a component is vulnerable to unify upgrade, you can see depend on circumstances intuitive, can resolve version conflicts.

2. Implement

Use spring provides dependency management plug-ins:
dependency management plug-ins and configuration methods: https://docs.spring.io/dependency-management-plugin/docs/1.0.8.RELEASE/reference/html/

1. The top module build.gradle add dependency management plug-ins

plugins {
    id "io.spring.dependency-management" version "1.0.6.RELEASE"
}
buildscript {
    repositories {
        maven { url 'https://repo.spring.io/plugins-snapshot' }
    }
    dependencies {
        classpath 'io.spring.gradle:dependency-management-plugin:1.0.7.BUILD-SNAPSHOT'
    }
}

apply plugin: "io.spring.dependency-management"

2. Add all management build.gradle top module dependencies

dependencyManagement {
    dependencies {
        dependency 'org.springframework:spring-core:4.0.3.RELEASE'
    }
}

3. sub-module build.gradle add free version of the package

dependencies {
    compile 'org.springframework:spring-core'
}

3. Examples

1. The top module build.gradle add dependency management plug
Here Insert Picture Description
Here Insert Picture Description
2. Add all the top-level management module build.gradle dependencies
Here Insert Picture Description
3. sub-module build.gradle add-free version of the package
Here Insert Picture Description

4. Management Principles

  • Add dependent sub-module packages need to be declared at the top level dependency management module
  • If the dependent sub-module packet does not exist in the top module, the top priority declared dependency management module
  • If the sub-module packages depend on the version of the top-level module dependency management declared inconsistent version, upgrade version dependency management priority top-level module declaration, followed by coverage in the sub-module package version dependencies
Published 418 original articles · won praise 745 · Views 1.26 million +

Guess you like

Origin blog.csdn.net/u013467442/article/details/98597222