Gradle工程构建基础配置

chd 6d64a49960 更新 'upload.gradle' 2 years ago
.gitignore f6139a0de3 '提交基础配置' 2 years ago
README.md f6139a0de3 '提交基础配置' 2 years ago
base.gradle f6139a0de3 '提交基础配置' 2 years ago
maven.gradle 79cf415fed 更新 'maven.gradle' 2 years ago
upload.gradle 6d64a49960 更新 'upload.gradle' 2 years ago
version.gradle f6139a0de3 '提交基础配置' 2 years ago

README.md

cecdhc-basic-gradle-base

Gradle工程统一Gradle全局配置

gradle相比maven配置灵活,可自定义更多的任务,但是当项目众多,每个项目都去维护一大堆gradle配置的时候,会发现版本变得很难管理,每个项目一个gradle.properties,公共组件,其他组件都无法达到统一维护版本的问题。 本文主要解决gradle将版本进行统一管理

项目使用

在项目最外层的build.gradle中

//buildscript不能省略,每个项目必须定义
buildscript {
    ext {
        gradleHome = 'http://192.168.16.201:8899/basic-public-component/itgdevfwk-public-group/cecdhc-basic-gradle-base/raw/master/'
    }
    //maven.gradle配置
    apply from: resources.text.fromInsecureUri(gradleHome + 'maven.gradle')
    //version.gradle配置
    apply from: resources.text.fromInsecureUri(gradleHome + 'version.gradle')
    //私库
    repositories {
        maven {
            allowInsecureProtocol = true
            url REPOSITORY_URL
        }
    }
    dependencies {
        classpath "io.spring.gradle:dependency-management-plugin:${gradleManagePluginVersion}"
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
apply from: resources.text.fromInsecureUri(gradleHome + 'base.gradle')

version = '1.0.0-SNAPSHOT'
group = 'cec.dhc.itgfwk.oauth'

dependencies {
	//模块引用
    implementation project(':demo-api')
}

项目模块使用

1.如项目的api模块,需要对外提供jar包到私库中时,使用方式如下 在模块下的build.gradle中配置

group 'cec.dhc.itgfwk.api.oauth'
apply from: resources.text.fromInsecureUri(gradleHome + 'upload.gradle')
dependencies {
    compileOnly ("io.swagger:swagger-annotations")
    compileOnly ("io.springfox:springfox-core")
    compileOnly ("javax.servlet:javax.servlet-api")
    compileOnly ("org.springframework:spring-web")
    compileOnly ("cec.dhc.plffwk.comps:cecdhc-plffwk-component")
    compileOnly ("cec.dhc.devfwk.starters.feign:cecdhc-devfwk-starters-feign")
}

2.非api模块使用

dependencies {
    implementation ("io.swagger:swagger-annotations")
}