Gradle多模块实践:dependencies的模组化导入

虽然maven和gradle能够自动处理依赖,但是觉得还不够。

当java引入一个新组件时。如果全部引入,则会导致引入过多的jar;如果指定组件的各个模块,又需要逐条引入,尤其当需要其它模块支持时,当子模块多了后维护困难。

我希望像POM那样,指定一个文件则引入了需要的一组组件。而且不用单独书写一个pom,因为一来每个模块要单独文件管理,二来不方便统一管理。于是寻找gradle脚本grovvy的实现方式。通过数小时的折腾,终于解决该问题。

这样我们可以把多个组件引入的包定义为一个列表,需要时直接引入列表来实现引入对应的模块。

需要给gradle的rootProject的build.gradle添加一个grovvy function,如下:


/**
模组化添加依赖 addSupportLibraries(dependencies, dependency_spring_boot_group)
@param dependencies 上级的dependencies
@param supportLibrary 定义的库列表
@param compileOnly 默认导入方式是否为仅编译compileOnly,

 定义的库列表可以是字符串,也可以是对象,对象可以包含excludes和transitive属性,属性解释如下:
 excludes: 需要排除的列表,传入一个对象,对象包括group和module属性。等同与每项书写exclude group: 'xxx', module: 'xxx'
 transitive: 是否排除下面所有依赖,如果为false,则排除所有。等同于书写: transitive = false

 Example1:

 implementation ("org.springframework.boot:spring-boot:${spring_boot_version}")
 implementation ("org.springframework.boot:spring-boot-starter:${spring_boot_version}")
 implementation ("org.springframework.boot:spring-boot-autoconfigure:${spring_boot_version}")

 书写为:
 rootProject.addSupportLibraries(dependencies, [
 "org.springframework.boot:spring-boot:${spring_boot_version}",
 "org.springframework.boot:spring-boot-starter:${spring_boot_version}",
 "org.springframework.boot:spring-boot-autoconfigure:${spring_boot_version}"
 ])

 或者分开引入:
 rootProject.addSupportLibraries(dependencies, [
 "org.springframework.boot:spring-boot:${spring_boot_version}"
 ])
 rootProject.addSupportLibraries(dependencies, [
 "org.springframework.boot:spring-boot-starter:${spring_boot_version}",
 "org.springframework.boot:spring-boot-autoconfigure:${spring_boot_version}"
 ])

 Example2:

 compileOnly ("org.springframework.security:spring-security-core:${spring_security_version}")
 compileOnly ("com.alicp.jetcache:jetcache-starter-redis-lettuce:${jetcache_version}"){
 exclude group: 'org.springframework.boot', module: 'spring-boot-starter'
 exclude group: 'org.springframework', module: 'spring-context'
 exclude group: 'org.slf4j', module: 'slf4j-api'
 }

 书写为:

 rootProject.addSupportLibraries(dependencies, [
   "org.springframework.security:spring-security-core:${spring_security_version}",
   [lib: "com.alicp.jetcache:jetcache-starter-redis-lettuce:${jetcache_version}",
     excludes:[
       [group: 'org.springframework.boot', module: 'spring-boot-starter'],
       [group: 'org.springframework', module: 'spring-context'],
       [group: 'org.slf4j', module: 'slf4j-api']
   ]]
 ],true)

 Example3:

 implementation ("org.xerial.snappy:snappy-java:1.1.8.4") // embedded ZOOKEEPER依赖,minio会提供
 compileOnly ("org.springframework.data:spring-data-elasticsearch:${spring_data_elasticsearch_version}"){
 transitive = false
 }

 书写为:
    rootProject.addSupportLibraries(dependencies, [
        "org.xerial.snappy:snappy-java:1.1.8.4",
        [lib: "org.springframework.data:spring-data-elasticsearch:${spring_data_elasticsearch_version}", transitive: false, compileOnly: true]
    ])

 这样就可以把每个开源模块需要的库都定义为一个列表,按需引入

 */
def addSupportLibraries(dependencies, supportLibrary, compileOnly = false){
    supportLibrary.each { library -> {
        if (library instanceof String || library instanceof org.codehaus.groovy.runtime.GStringImpl) {
            if (compileOnly) {
                dependencies.compileOnly library
            } else {
                dependencies.implementation library
            }
        } else { // 使用对象,定义每个属性
            var ifCompile = compileOnly
            if(library?.compileOnly) {
                ifCompile = library.compileOnly //内部定义的优先级更高
            }
            var doResult;
            // 先执行操作
            if (ifCompile) {
                doResult = dependencies.compileOnly library.lib
            } else {
                doResult = dependencies.implementation library.lib
            }
            // 操作exclude
            if (library?.excludes) {
                library.excludes.each { excludeObj ->  {
                    doResult.exclude(excludeObj)
                }}
            }
            // 操作 transitive = false
            if (library?.transitive == false) {
                doResult.exclude(module: '*')
            }
        }
    }}
}

这样就可以对依赖项目的模块统一组件维护了。

我的gradle项目组织如下:

ccframe-simple
+--- ccframe-common
+--- ccframe-demo
+--- ccframe-service
+--- ccframe-web

在根项目ccframe-simple的build.gradle:
 

//系统启动初始化:自动下载插件
def repoConfig = {
    all { ArtifactRepository repo ->
        if (repo instanceof MavenArtifactRepository) {
            def url = repo.url.toString()
            if (url.contains('repo1.maven.org/maven2')
                    || url.contains('repo.maven.org/maven2')
                    || url.contains('repo.maven.apache.org/maven2')
                    || url.contains('jcenter.bintray.com')
                    || url.contains('maven.google.com')
                    || url.contains('plugins.gradle.org/m2')
                    || url.contains('repo.spring.io/libs-milestone')
                    || url.contains('repo.spring.io/plugins-release')
                    || url.contains('repo.grails.org/grails/core')
                    || url.contains('repository.apache.org/snapshots')
            ) {
                println "gradle init: [buildscript.repositories] (${repo.name}: ${repo.url}) removed"
                remove repo
            }
        }
    }

    // Maven 镜像聚合了:central、jcenter、google、gradle-plugin
    maven { url 'https://maven.aliyun.com/repository/central' }
    maven { url 'https://maven.aliyun.com/repository/jcenter' }
    maven { url 'https://maven.aliyun.com/repository/google' }
    maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
    maven { url 'https://maven.aliyun.com/repository/public/' }
    mavenLocal() //缺失的库添加到本地
}

subprojects {
    buildscript {
        repositories repoConfig
    }
    repositories repoConfig

    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/gradle-plugin'
        }
    }

    group = 'org.ccframe'
    version = '1.0-SNAPSHOT'
    //---------------------- 版本定义 ----------------------//
    ext {
        spring_boot_version = '2.3.12.RELEASE'
        jul_to_slf4j_version = '1.7.36'
        spring_version = '5.2.20.RELEASE'
        spring_cloud_version = '2.2.9.RELEASE'
        spring_cloud_zookeeper_discovery_version = '2.2.5.RELEASE'
        zookeeper_version = '3.7.1'
        spring_data_version = '2.3.9.RELEASE'
        spring_data_elasticsearch_version = '4.0.9.RELEASE'
        lombok_version = '1.18.30'
        common_lang3_version = '3.12.0'
        hibernate_jpa_version = '1.0.2.Final'
        hibernate_version = '5.4.33.Final'
        spring_security_version = '5.3.3.RELEASE'
        commons_fileupload_version = '1.3.3'
        jjwt_version = '0.9.1'
        fastjson_version = '1.2.62'
        dubbo_version = '3.1.11'
        commons_io_version = '2.11.0'
        curator_version = '5.4.0'
        swagger_version = '2.9.2'
        shardingsphere_version = '5.2.1'
        druid_version = '1.1.23'
        jetcache_version = '2.7.5'
        redisson_version = '3.19.3' //netty兼容版本
        mysql_connector_version = '8.0.33'
        h2_version = '2.2.224'
        snakeyaml_version = '1.33' //shardingshere依赖
        elasticsearch_version = '7.8.1'
        spring_boot_admin_version = '2.3.1'
        elasticsearch_painless_asm_version = '7.2'
        dbunit_version = '2.5.4'
        minio_version = '8.4.6'
        kryo_version = '5.6.0' // 这个是redission依赖的
        kryo5_version = '5.5.0' // jetcache还是依赖的这个旧版
        swagger2_version = '2.9.2'
        zxing_version = '3.4.1'
        jackson_version = '2.11.4' //runtime需要单独引入jackson的jar
        quartz_version = '2.3.2'
        x_file_storage_version = '2.1.0'
        aliyun_sdk_oss_version = '3.17.4'
        okhttp_version = '4.12.0'
        just_auth_version = '1.16.6'
        just_auth_starter_version = '1.4.0'

        dependency_base_libs = [ // 基础依赖库
            "org.springframework.boot:spring-boot:${spring_boot_version}",
            "org.springframework.boot:spring-boot-autoconfigure:${spring_boot_version}",
            "org.springframework.boot:spring-boot-starter-log4j2:${spring_boot_version}",
            "org.apache.commons:commons-lang3:${common_lang3_version}",
            "commons-io:commons-io:${commons_io_version}",
            'org.apache.commons:commons-collections4:4.4',
            "org.springframework:spring-context-support:${spring_version}",
            'uk.org.lidalia:sysout-over-slf4j:1.0.2',  //system out err stacktrace转slf4j,便于统一日志
        ]
        dependency_db_libs = [ // 数据库相关依赖库
            "org.springframework.data:spring-data-jpa:${spring_data_version}",
            "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:${hibernate_jpa_version}",
            "org.hibernate:hibernate-core:${hibernate_version}",
            [lib: "org.apache.shardingsphere:shardingsphere-jdbc-core-spring-boot-starter:${shardingsphere_version}",
            excludes:[
                    [group: 'org.apache.shardingsphere', module: 'shardingsphere-sharding-cosid'], //cosid算法会引用更高版本spring
                    [group: 'io.vertx',  module: 'vertx-mysql-client'] // 该驱动已不使用
            ]],
            "com.h2database:h2:${h2_version}", // shardingsphere依赖
            "org.yaml:snakeyaml:${snakeyaml_version}", // shardingsphere版本依赖
            "com.alibaba:druid:${druid_version}",
            "mysql:mysql-connector-java:${mysql_connector_version}",
            "org.dbunit:dbunit:${dbunit_version}", //不要升级
            'org.apache.ant:ant:1.9.9' // DBUnit使用
        ]
        dependency_es_libs = [ // ES依赖库 embeded ES 7.6.2 -> 7.8.1
            "org.elasticsearch:elasticsearch:${elasticsearch_version}",
            "org.elasticsearch.client:transport:${elasticsearch_version}",
            "org.elasticsearch:elasticsearch-plugin-classloader:${elasticsearch_version}",
            "org.elasticsearch.client:elasticsearch-rest-high-level-client:${elasticsearch_version}",
            "org.elasticsearch.plugin:transport-netty4-client:${elasticsearch_version}",
            "org.ow2.asm:asm:${elasticsearch_painless_asm_version}", //elasticserach依赖
            "org.springframework.data:spring-data-elasticsearch:${spring_data_elasticsearch_version}"
        ]
        dependency_zk_libs = [ // embedded ZOOKEEPER依赖库
            "org.apache.zookeeper:zookeeper:${zookeeper_version}",
            "org.apache.curator:curator-x-discovery:${curator_version}",
            "io.dropwizard.metrics:metrics-core:3.2.6",
            "org.xerial.snappy:snappy-java:1.1.8.4"
        ]
        dependency_web_libs = [ // web 相关库,
            "org.springframework.boot:spring-boot-starter-security:${spring_boot_version}",
            "commons-fileupload:commons-fileupload:${commons_fileupload_version}",
            "com.google.zxing:javase:${zxing_version}",
            'javax.servlet:javax.servlet-api:4.0.1',
            [lib: 'javax.servlet.jsp:jsp-api:2.2', compileOnly: true]
        ]
        dependency_security_libs = [ // 权限和三方鉴权相关库,
            "io.jsonwebtoken:jjwt:${jjwt_version}", // token 方案
            "org.springframework.boot:spring-boot-starter-security:${spring_boot_version}",
            "me.zhyd.oauth:JustAuth:${just_auth_version}", //多渠道登录
            "com.xkcoding:justauth-spring-boot-starter:${just_auth_starter_version}"
        ]
        dependency_webapi_libs = [ // 在线API接口相关库,
            "io.springfox:springfox-swagger2:${swagger_version}",
            'io.github.wilson-he:swagger2-spring-boot-starter:1.1.2',
            [lib: "com.github.xiaoymin:knife4j-spring-boot-autoconfigure:2.0.9",
            excludes:[
                    [group: 'com.github.xiaoymin', module: 'knife4j-spring']
            ]],
            'com.github.xiaoymin:knife4j-spring-ui:2.0.9',
        ]
        dependency_redission_libs = [ // redission缓存相关库
            "org.redisson:redisson:${redisson_version}",
            "com.esotericsoftware:kryo:${kryo_version}" // redission使用的是这个
        ]
        dependency_jetcache_libs = [ // redission缓存相关库
            [lib: "com.alicp.jetcache:jetcache-starter-redis-lettuce:${jetcache_version}",
            excludes:[
                  [group: 'org.springframework.boot', module: 'spring-boot-starter'],
                  [group: 'org.springframework', module: 'spring-context'],
                  [group: 'org.slf4j', module: 'slf4j-api'],
            ]],
            "com.esotericsoftware.kryo:kryo5:${kryo5_version}" //混乱的kryo,弄两个包。。。,这个已不再升级,jetcache引入,将来会替换掉
        ]
        dependency_actuator_libs = [ // 性能监控相关库
             "org.springframework.boot:spring-boot-starter-actuator:${spring_boot_version}",
             "org.latencyutils:LatencyUtils:2.0.3"
        ]
        dependency_files_libs = [ // OSS文件系统相关库,OSS实现本地、MINIO、阿里云3个
            "org.dromara.x-file-storage:x-file-storage-spring:${x_file_storage_version}",  //多存储系统
            'net.coobird:thumbnailator:0.4.8',
            "com.squareup.okhttp3:okhttp:${okhttp_version}", //要强制绑定4.X版本,否则MINIO会出错
            "io.minio:minio:${minio_version}", // minio驱动
            "com.aliyun.oss:aliyun-sdk-oss:${aliyun_sdk_oss_version}" //阿里云OSS驱动
        ]

    }

    //dubbo_version = '3.1.11'
    //classpath 'io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:1.0.15.RELEASE'

    //---------------------- JAVA 编译插件 ----------------------//
    apply plugin: 'java'
    apply plugin: 'java-library'
    apply plugin: 'maven-publish' //发布到本地
    apply plugin: 'idea'
    idea {
        module {
            downloadSources = true
        }
    }

    //JAVA 文件编码
    compileJava.options.encoding = 'UTF-8'
    tasks.withType(JavaCompile) {
        options.debug = true //输出行号
        options.debugOptions.debugLevel = "source,lines,vars" //输出行号
        options.encoding = "UTF-8"
    }

    // unset ANDROID_HOME to avoid problems with zxing
    System.setProperty("env.ANDROID_HOME", "");

    tasks.withType(Copy) {
        duplicatesStrategy = DuplicatesStrategy.EXCLUDE //忽略resource重复资源
    }

    configurations.all {
        //transitive = false //默认不自动关联依赖,以免打包过大
        resolutionStrategy.cacheChangingModulesFor 0, 'seconds' //立即检查而不是要过24h,因为有snapshot
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' // 不要logback要log4j2
    }
    //公共需要的库
    dependencies {
        compileOnly 'org.projectlombok:lombok:1.18.30'
        compileOnly "org.springframework.boot:spring-boot-configuration-processor:${spring_boot_version}"
        annotationProcessor 'org.projectlombok:lombok:1.18.30'
        annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:${spring_boot_version}"
        testAnnotationProcessor 'org.projectlombok:lombok:1.18.30'
        testAnnotationProcessor "org.springframework.boot:spring-boot-configuration-processor:${spring_boot_version}"
        //参与测试不进行发布
        testImplementation 'org.projectlombok:lombok:1.18.30'
        testImplementation 'junit:junit:4.8' //4.11的版本需要额外包
    }

}

/**
模组化添加依赖 addSupportLibraries(dependencies, dependency_spring_boot_group)
@param dependencies 上级的dependencies
@param supportLibrary 定义的库列表
@param compileOnly 默认导入方式是否为仅编译compileOnly,

 定义的库列表可以是字符串,也可以是对象,对象可以包含excludes和transitive属性,属性解释如下:
 excludes: 需要排除的列表,传入一个对象,对象包括group和module属性。等同与每项书写exclude group: 'xxx', module: 'xxx'
 transitive: 是否排除下面所有依赖,如果为false,则排除所有。等同于书写: transitive = false

 Example1:

 implementation ("org.springframework.boot:spring-boot:${spring_boot_version}")
 implementation ("org.springframework.boot:spring-boot-starter:${spring_boot_version}")
 implementation ("org.springframework.boot:spring-boot-autoconfigure:${spring_boot_version}")

 书写为:
 rootProject.addSupportLibraries(dependencies, [
 "org.springframework.boot:spring-boot:${spring_boot_version}",
 "org.springframework.boot:spring-boot-starter:${spring_boot_version}",
 "org.springframework.boot:spring-boot-autoconfigure:${spring_boot_version}"
 ])

 或者分开引入:
 rootProject.addSupportLibraries(dependencies, [
 "org.springframework.boot:spring-boot:${spring_boot_version}"
 ])
 rootProject.addSupportLibraries(dependencies, [
 "org.springframework.boot:spring-boot-starter:${spring_boot_version}",
 "org.springframework.boot:spring-boot-autoconfigure:${spring_boot_version}"
 ])

 Example2:

 compileOnly ("org.springframework.security:spring-security-core:${spring_security_version}")
 compileOnly ("com.alicp.jetcache:jetcache-starter-redis-lettuce:${jetcache_version}"){
 exclude group: 'org.springframework.boot', module: 'spring-boot-starter'
 exclude group: 'org.springframework', module: 'spring-context'
 exclude group: 'org.slf4j', module: 'slf4j-api'
 }

 书写为:

 rootProject.addSupportLibraries(dependencies, [
   "org.springframework.security:spring-security-core:${spring_security_version}",
   [lib: "com.alicp.jetcache:jetcache-starter-redis-lettuce:${jetcache_version}",
     excludes:[
       [group: 'org.springframework.boot', module: 'spring-boot-starter'],
       [group: 'org.springframework', module: 'spring-context'],
       [group: 'org.slf4j', module: 'slf4j-api']
   ]]
 ],true)

 Example3:

 implementation ("org.xerial.snappy:snappy-java:1.1.8.4") // embedded ZOOKEEPER依赖,minio会提供
 compileOnly ("org.springframework.data:spring-data-elasticsearch:${spring_data_elasticsearch_version}"){
 transitive = false
 }

 书写为:
    rootProject.addSupportLibraries(dependencies, [
        "org.xerial.snappy:snappy-java:1.1.8.4",
        [lib: "org.springframework.data:spring-data-elasticsearch:${spring_data_elasticsearch_version}", transitive: false, compileOnly: true]
    ])

 这样就可以把每个开源模块需要的库都定义为一个列表,按需引入

 */
def addSupportLibraries(dependencies, supportLibrary, compileOnly = false){
    supportLibrary.each { library -> {
        if (library instanceof String || library instanceof org.codehaus.groovy.runtime.GStringImpl) {
            if (compileOnly) {
                dependencies.compileOnly library
            } else {
                dependencies.implementation library
            }
        } else { // 使用对象,定义每个属性
            var ifCompile = compileOnly
            if(library?.compileOnly) {
                ifCompile = library.compileOnly //内部定义的优先级更高
            }
            var doResult;
            // 先执行操作
            if (ifCompile) {
                doResult = dependencies.compileOnly library.lib
            } else {
                doResult = dependencies.implementation library.lib
            }
            // 操作exclude
            if (library?.excludes) {
                library.excludes.each { excludeObj ->  {
                    doResult.exclude(excludeObj)
                }}
            }
            // 操作 transitive = false
            if (library?.transitive == false) {
                doResult.exclude(module: '*')
            }
        }
    }}
}

这样按照基础功能域划分成了11个块:

  1. 基础依赖库
  2. 数据库相关依赖库
  3. ES依赖库 embeded ES
  4. embedded ZOOKEEPER依赖库
  5. web 相关库
  6. 权限和三方鉴权相关库
  7. 在线API接口相关库
  8. redission缓存相关库
  9. jetcache缓存相关库
  10. 性能监控相关库
  11. OSS文件系统相关库

需要时直接导入对应的功能组即可,可以方便的在子模块里复用,统一在主模块里维护。

原来子项目ccframe-service的build.gradle里的dependencies:

dependencies {
    implementation project(':ccframe-common')
    implementation project(':ccframe-api')
    implementation ("org.springframework.boot:spring-boot:${spring_boot_version}")
    implementation ("org.springframework.boot:spring-boot-autoconfigure:${spring_boot_version}")
    implementation ("org.springframework.boot:spring-boot-starter-quartz:${spring_boot_version}")
    implementation ("org.apache.dubbo:dubbo-spring-boot-starter:${dubbo_version}")
    implementation ("org.apache.shardingsphere:shardingsphere-jdbc-core-spring-boot-starter:${shardingsphere_version}") {
        exclude group: 'org.apache.shardingsphere', module: 'shardingsphere-sharding-cosid' //cosid算法会引用更高版本spring
    }
    implementation ("org.springframework.boot:spring-boot-starter-log4j2:${spring_boot_version}")
    implementation ("org.springframework.boot:spring-boot-starter-actuator:${spring_boot_version}")

    //implementation "org.springframework.boot:spring-boot-starter-data-redis:${spring_boot_version}"
    implementation ("org.redisson:redisson:${redisson_version}")

    implementation ("org.springframework:spring-context-support:${spring_version}")

    implementation ("org.springframework.data:spring-data-elasticsearch:${spring_data_elasticsearch_version}")
    implementation ("org.apache.commons:commons-lang3:${common_lang3_version}")
    implementation ("org.springframework.data:spring-data-jpa:${spring_data_version}")
    implementation ("commons-io:commons-io:${commons_io_version}")
    //implementation ("org.apache.curator:curator-x-discovery:${curator_version}") //zk需要
    implementation ("com.alibaba:druid:${druid_version}")
    implementation ("mysql:mysql-connector-java:${mysql_connector_version}")
    implementation ("org.hibernate:hibernate-core:${hibernate_version}")

    //embeded ES 7.6.2 -> 7.8.1
    implementation ("org.elasticsearch:elasticsearch:${elasticsearch_version}")
    implementation ("org.elasticsearch.client:transport:${elasticsearch_version}")
    implementation ("org.elasticsearch:elasticsearch-plugin-classloader:${elasticsearch_version}")
    implementation ("org.elasticsearch.client:elasticsearch-rest-high-level-client:${elasticsearch_version}")
    implementation ("org.elasticsearch.plugin:transport-netty4-client:${elasticsearch_version}")

    implementation ("com.alicp.jetcache:jetcache-starter-redis-lettuce:${jetcache_version}"){
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter'
        exclude group: 'org.springframework', module: 'spring-context'
        exclude group: 'org.slf4j', module: 'slf4j-api'
    }
    implementation ("com.h2database:h2:${h2_version}")// shardingsphere依赖
    implementation ("org.yaml:snakeyaml:${snakeyaml_version}") // shardingsphere版本依赖
    implementation ("org.ow2.asm:asm:${elasticsearch_painless_asm_version}") //elasticserach依赖
    implementation ("org.dbunit:dbunit:${dbunit_version}") //不要升级
    implementation ('org.apache.ant:ant:1.9.9') // DBUnit使用
    implementation ("io.minio:minio:${minio_version}") //minio分布式文件
    //implementation ("org.quartz-scheduler:quartz-jobs:${quartz_version}")

    implementation ("com.esotericsoftware:kryo:${kryo_version}") //混乱的kryo,弄两个包,被不同的项目引用。。。
    implementation ("com.esotericsoftware.kryo:kryo5:${kryo5_version}") //混乱的kryo,弄两个包。。。,这个已不再升级

    implementation ("io.dropwizard.metrics:metrics-core:3.2.6") // embedded ZOOKEEPER依赖

    //下面几个是服务器独立运行时需要的jar
    implementation ("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${jackson_version}")
    implementation ("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:${jackson_version}")
    implementation ("org.latencyutils:LatencyUtils:2.0.3")

    implementation ("org.dromara.x-file-storage:x-file-storage-spring:${x_file_storage_version}") //多存储系统

    implementation ("com.squareup.okhttp3:okhttp:${okhttp_version}") //要强制绑定4.X版本,否则MINIO会出错

    //implementation "org.slf4j:jul-to-slf4j:${jul_to_slf4j_version}"
    //implementation "org.slf4j:jul-to-slf4j:${jul_to_slf4j_version}"

    implementation ('org.apache.commons:commons-collections4:4.4')
    implementation ('org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final')
    implementation ('uk.org.lidalia:sysout-over-slf4j:1.0.2') //system out err stacktrace转slf4j,便于统一日志
    implementation ('net.coobird:thumbnailator:0.4.8') //缩略图支持,下一步替换统一OSS引擎
    implementation ('javax.servlet:javax.servlet-api:4.0.1')

    compileOnly ('javax.servlet.jsp:jsp-api:2.2')
}

在根项目按照功能块划分后,使用    rootProject.addSupportLibraries 来导入,这样就清晰多了:
 

dependencies {
    implementation project(':ccframe-common')
    implementation project(':ccframe-api')
    rootProject.addSupportLibraries(dependencies, dependency_base_libs)
    rootProject.addSupportLibraries(dependencies, dependency_es_libs)
    rootProject.addSupportLibraries(dependencies, dependency_db_libs)
    rootProject.addSupportLibraries(dependencies, dependency_jetcache_libs)
    rootProject.addSupportLibraries(dependencies, dependency_redission_libs)
    rootProject.addSupportLibraries(dependencies, dependency_zk_libs)
    rootProject.addSupportLibraries(dependencies, dependency_files_libs)
    rootProject.addSupportLibraries(dependencies, dependency_actuator_libs)
    implementation ("org.apache.dubbo:dubbo-spring-boot-starter:${dubbo_version}")
    implementation ("org.springframework.boot:spring-boot-starter-quartz:${spring_boot_version}")
}

其中dubbo和quart只需要一个包即可统一维护,故不用分组管理。

仅编译的common模块dependencies 重新整理后如下:

dependencies {
    implementation project(':ccframe-api')

    rootProject.addSupportLibraries(dependencies, dependency_base_libs, true)
    rootProject.addSupportLibraries(dependencies, dependency_es_libs, true)
    rootProject.addSupportLibraries(dependencies, dependency_db_libs, true)
    rootProject.addSupportLibraries(dependencies, dependency_jetcache_libs, true)
    rootProject.addSupportLibraries(dependencies, dependency_redission_libs, true)
    rootProject.addSupportLibraries(dependencies, dependency_zk_libs, true)
    rootProject.addSupportLibraries(dependencies, dependency_web_libs, true)
    rootProject.addSupportLibraries(dependencies, dependency_files_libs, true)
    rootProject.addSupportLibraries(dependencies, dependency_actuator_libs, true)
    compileOnly ("org.apache.dubbo:dubbo:${dubbo_version}")

    compileOnly ("io.jsonwebtoken:jjwt:${jjwt_version}") //token方案
}

看看,改造后是不是清爽多了。这样我们只需要在根项目的build.gradle统一维护列表,在子项目里按需引入整个组件依赖模块就行了,不用再逐条去implementation。方便,太方便了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值