Gradle统一版本号控制

之前我们在gradle中引入依赖如下所示:

dependencies {

    compile group: 'org.springframework', name: 'spring-webmvc', version: '5.1.14.RELEASE'
    compile group: 'org.springframework', name: 'spring-context', version: '5.1.14.RELEASE'

    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.13.0'
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.0'

    testCompile group: 'junit', name: 'junit', version: '4.12'
}

这种方式,当引入依赖过多,要更改版本号的时候就需要一个个去找,下面用ext创建键值对来存放版本号,需要改版本的时候改ext里的值就行了。

ext{

    springMVCVersion        = '5.1.14.RELEASE'
    springContextVersion    = '5.1.14.RELEASE'
    log4jVersion            = '2.13.0'
    junitVersion			= '4.12'
}

dependencies {

    compile group: 'org.springframework', name: 'spring-webmvc', version: springMVCVersion
    compile group: 'org.springframework', name: 'spring-context', version: springContextVersion

    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: log4jVersion
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: log4jVersion

    testCompile group: 'junit', name: 'junit', version: junitVersion
}

你可能感兴趣的:(Gradle,JAVA)