Parcourir la source

'提交基础配置'

ranhui il y a 2 ans
commit
f6139a0de3
6 fichiers modifiés avec 413 ajouts et 0 suppressions
  1. 2 0
      .gitignore
  2. 62 0
      README.md
  3. 177 0
      base.gradle
  4. 26 0
      maven.gradle
  5. 65 0
      upload.gradle
  6. 81 0
      version.gradle

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+### IntelliJ IDEA ###
+.idea

+ 62 - 0
README.md

@@ -0,0 +1,62 @@
+# cecdhc-basic-gradle-base
+Gradle工程统一Gradle全局配置
+
+gradle相比maven配置灵活,可自定义更多的任务,但是当项目众多,每个项目都去维护一大堆gradle配置的时候,会发现版本变得很难管理,每个项目一个gradle.properties,公共组件,其他组件都无法达到统一维护版本的问题。
+本文主要解决gradle将版本进行统一管理
+### 项目使用
+在项目最外层的build.gradle中
+
+```groovy
+//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中配置
+```groovy
+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模块使用
+```groovy
+dependencies {
+    implementation ("io.swagger:swagger-annotations")
+}
+```

+ 177 - 0
base.gradle

@@ -0,0 +1,177 @@
+configure(allprojects) { project ->
+    apply plugin: 'org.springframework.boot'
+    apply plugin: 'io.spring.dependency-management'
+    apply plugin: 'java'
+    apply plugin: 'idea'
+    sourceCompatibility = 1.8
+    targetCompatibility = 1.8
+    configurations {
+        developmentOnly
+        runtimeClasspath {
+            extendsFrom developmentOnly
+        }
+        compileOnly {
+            extendsFrom annotationProcessor
+        }
+    }
+    // java编译的时候缺省状态下会因为中文字符而失败
+    [compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'
+    dependencyManagement {
+        overriddenByDependencies = true
+        imports {
+            mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
+            mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
+            mavenBom "com.alibaba.cloud:spring-cloud-alibaba-dependencies:${springCloudAlibabaVersion}"
+        }
+        dependencies {
+            dependency "cec.dhc.plffwk.comps:cecdhc-plffwk-component:${cecdhcFwkCommsVersion}"
+            dependency "cec.dhc.plffwk.tools:cecdhc-plffwk-utils:${cecdhcFwkUtilsVersion}"
+            dependency "cec.dhc.devfwk.starters.knife4j:cecdhc-devfwk-starters-knife4j:${cecdhcKnife4jStarterVersion}"
+            dependency "cec.dhc.devfwk.starters.web:cecdhc-devfwk-starters-web:${cecdhcWebStarterVersion}"
+            dependency "cec.dhc.devfwk.starters.log:cecdhc-devfwk-starters-log:${cecdhcLogStarterVersion}"
+            dependency "cec.dhc.devfwk.starters.redis:cecdhc-devfwk-starters-redis:${cecdhcRedisStarterVersion}"
+            dependency "cec.dhc.devfwk.starters.nacos:cecdhc-devfwk-starters-nacos:${cecdhcNacosStarterVersion}"
+            dependency "cec.dhc.devfwk.starters.mybatis:cecdhc-devfwk-starters-mybatis:${cecdhcMybatisStarterVersion}"
+            dependency "cec.dhc.devfwk.starters.feign:cecdhc-devfwk-starters-feign:${cecdhcFeignStarterVersion}"
+            dependency "cec.dhc.devfwk.starters.minio:cecdhc-devfwk-starters-minio:${cecdhcMinioStarterVersion}"
+            dependency "cec.dhc.devfwk.starters.sentinel:cecdhc-devfwk-starters-sentinel:${cecdhSentinelStarterVersion}"
+            dependency "cec.dhc.devfwk.starters.shiro:cecdhc-devfwk-starters-shiro:${cecdhcShiroStarterVersion}"
+            dependency "cec.dhc.devfwk.starters.dingding:cecdhc-devfwk-starters-dingding:${cecdhcDingdingStarterVersion}"
+
+            //security包
+            dependency "org.springframework.security:spring-security-core:${springSecurityVersion}"
+            dependency "org.springframework.security:spring-security-crypto:${springSecurityVersion}"
+            dependency "org.springframework.security:spring-security-config:${springSecurityVersion}"
+            dependency "org.springframework.security:spring-security-web:${springSecurityVersion}"
+            dependency "org.springframework.security:spring-security-oauth2-jose:${springSecurityVersion}"
+            dependency "org.springframework.security.oauth:spring-security-oauth2:${springSecurityOauth2Version}"
+            dependency "org.springframework.security:spring-security-jwt:${springSecurityJwtVersion}"
+            dependency "com.nimbusds:nimbus-jose-jwt:${nimbusJoseJwtVersion}"
+
+            //其他包
+            dependency "com.github.xiaoymin:knife4j-micro-spring-boot-starter:${knife4jVersion}"
+            dependency "com.github.xiaoymin:knife4j-spring-ui:${knife4jVersion}"
+            dependency "org.hibernate.validator:hibernate-validator:${hibernateValidatorVersion}"
+
+            dependency "com.baomidou:mybatis-plus-boot-starter:${mybatisPlusVersion}"
+            dependency "com.baomidou:mybatis-plus-annotation:${mybatisPlusVersion}"
+
+            dependency "javax.servlet:javax.servlet-api:${javaxServletVersion}"
+
+            dependency "io.springfox:springfox-core:${springFoxVersion}"
+            dependency "io.swagger:swagger-annotations:${swaggerAnnotationVersion}"
+
+            dependency "org.redisson:redisson:${redissonVersion}"
+            dependency "io.github.openfeign:feign-core:${feignCoreVersion}"
+
+            dependency "cn.hutool:hutool-all:${hutoolVersion}"
+            dependency "commons-io:commons-io:${commonsIoVersion}"
+            dependency "commons-codec:commons-codec:${commonsCodecVersion}"
+            dependency "org.apache.commons:commons-lang3:${commLang3Version}"
+            dependency "org.apache.commons:commons-compress:${commonsCompressVersion}"
+            dependency "commons-beanutils:commons-beanutils:${beanUtilsVersion}"
+            dependency "org.apache.commons:commons-collections4:${collections4Version}"
+
+            dependency "com.alibaba:transmittable-thread-local:${threadLocalVersion}"
+            dependency "com.github.ben-manes.caffeine:caffeine:${caffeineVersion}"
+
+            dependency "cn.stylefeng.roses:pinyin-sdk-pinyin4j:${pinyin4jVersion}"
+            dependency "com.esotericsoftware:reflectasm:${reflectasmVersion}"
+            dependency "org.lionsoul:ip2region-spring-boot-starter:${ip2regionVersion}"
+            dependency "net.coobird:thumbnailator:${thumbnailatorVersion}"
+
+            dependency "org.apache.commons:commons-pool2:${commonsPool2Version}"
+            dependency "org.apache.httpcomponents:httpclient:${httpclientVersion}"
+            dependency "org.apache.httpcomponents:httpmime:${httpclientVersion}"
+            dependency "org.aspectj:aspectjweaver:${aspectjweaverVersion}"
+
+            dependency "com.github.whvcse:easy-captcha:${easyCaptchaVersion}"
+            dependency "com.github.ulisesbocchio:jasypt-spring-boot-starter:${jasyptSpringBootVersion}"
+
+            dependency "com.aliyun:alibaba-dingtalk-service-sdk:${dingtalkVersion}"
+            dependency "com.google.guava:guava:${guavaVersion}"
+            dependency "com.google.code.gson:gson:${gsonVersion}"
+            dependency "com.squareup.okhttp3:okhttp:${okhttpVersion}"
+            dependency "io.minio:minio:${minioVersion}"
+            dependency "org.springframework.security:spring-security-ldap:${securityLdapVersion}"
+
+            //数据库驱动
+            dependency "mysql:mysql-connector-java:${mysqlVersion}"
+            dependency "com.oracle.database.jdbc:ojdbc8:${oracleVersion}"
+            dependency "com.microsoft.sqlserver:sqljdbc4:${sqljdbcVersion}"
+            dependency "org.postgresql:postgresql:${postgresqlVersion}"
+            dependency "com.ibm.db2:db2jcc4:${db2Version}"
+            dependency "net.sourceforge.jtds:jtds:${jtdsVersion}"
+            dependency "io.jsonwebtoken:jjwt-api:${jjwtVersion}"
+            dependency "com.auth0:java-jwt:${javaJwtVersion}"
+            dependency "org.apache.shiro:shiro-spring:${shiroVersion}"
+            dependency " org.springframework.session:spring-session-data-redis:${sessionDataRedisVersion}"
+
+            dependency "com.alibaba.nacos:nacos-client:${nacosAlibabaVersion}"
+            dependency "com.alibaba.nacos:nacos-common:${nacosAlibabaVersion}"
+            dependency "com.alibaba.nacos:nacos-api:${nacosAlibabaVersion}"
+        }
+    }
+    dependencies {
+        compile "org.slf4j:slf4j-api:${slf4jApiVersion}"
+        annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
+        compile "org.hibernate.validator:hibernate-validator:${hibernateValidatorVersion}"
+    }
+    test {
+        useJUnitPlatform()
+    }
+    idea {
+        module {
+            inheritOutputDirs = true
+        }
+    }
+    sourceSets {
+        main {
+            output.resourcesDir = java.outputDir
+        }
+    }
+}
+configure(rootProject) { project ->
+    bootJar {
+        enabled(true)
+    }
+}
+configure(subprojects) { project ->
+    jar {
+        classifier = ''
+        enabled(true)
+    }
+    bootJar {
+        enabled = false
+    }
+    sourceSets {
+        main {
+            java {
+                srcDir 'src/main/java'
+            }
+            resources {
+                srcDir 'src/main/java'
+                srcDir 'src/main/resources'
+            }
+        }
+    }
+
+}
+if (JavaVersion.current().isJava8Compatible()) {
+    allprojects {
+        tasks.withType(Javadoc) {
+            options.encoding = 'UTF-8'
+            options.addStringOption('Xdoclint:none', '-quiet') // 关闭JDK1.8的doclint特性
+        }
+    }
+}
+configurations.all {
+    resolutionStrategy.cacheDynamicVersionsFor 0, 'seconds'
+    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
+    //当遇到版本冲突时,强制使用指定版本号。(会自动下载,无需在dependencies中配置)
+    resolutionStrategy.force([
+            "com.alibaba.nacos:nacos-client:${nacosAlibabaVersion}",
+            "com.alibaba.nacos:nacos-api:${nacosAlibabaVersion}",
+            "com.alibaba.nacos:nacos-common:${nacosAlibabaVersion}"
+    ])
+}

+ 26 - 0
maven.gradle

@@ -0,0 +1,26 @@
+ext {
+    REPOSITORY_HOME = 'http://nexus.galaksiodatanubo.work/repository'
+    REPOSITORY_URL =  REPOSITORY_HOME + "/maven-public/"
+    REPOSITORY_RELEASE_URL =  REPOSITORY_HOME + "/maven-releases/"
+    REPOSITORY_SNAPSHOT_URL =  REPOSITORY_HOME + "/maven-snapshots/"
+}
+allprojects {
+    repositories {
+        all {ArtifactRepository repo ->
+            def url = repo.url.toString()
+            if (repo instanceof MavenArtifactRepository && (url.startsWith("https://repo1.maven.org/maven2") || url.startsWith('https://jcenter.bintray.com/'))) {
+                project.logger.warn "Repository ${repo.url} removed."
+                remove repo
+            }
+        }
+        mavenLocal()
+        maven {
+            allowInsecureProtocol = true
+            url REPOSITORY_URL
+        }
+        maven {
+            allowInsecureProtocol = true
+            url REPOSITORY_SNAPSHOT_URL
+        }
+    }
+}

+ 65 - 0
upload.gradle

@@ -0,0 +1,65 @@
+// 打包源代码,为了方便查看源码及调试,把源码也上传到nexus仓库中
+task sourcesJar(type: Jar, dependsOn: classes) {
+    archiveClassifier = 'sources'
+    from sourceSets.main.allSource
+}
+// 打javadoc包,为了方便查看注释,需要把javadoc也上传到nexus仓库中
+task javadocJar(type: Jar, dependsOn: javadoc) {
+    classifier = 'javadoc'
+    from javadoc.destinationDir
+}
+tasks.withType(Javadoc) {
+    options.addStringOption('Xdoclint:none', '-quiet')
+    options.addStringOption('encoding', 'UTF-8')
+    options.addStringOption('charSet', 'UTF-8')
+}
+artifacts {
+    archives sourcesJar
+    archives javadocJar
+}
+
+apply plugin: 'maven-publish'
+
+publishing {
+    publications {
+        maven(MavenPublication) {
+            groupId this.group
+            artifactId project.name
+            if ("unspecified".equals(project.version)) {
+                version parent.version
+            } else {
+                version project.version
+            }
+            from components.java
+            versionMapping {
+                usage('java-api') {
+                    fromResolutionOf('runtimeClasspath')
+                }
+                usage('java-runtime') {
+                    fromResolutionResult()
+                }
+            }
+            artifact sourcesJar
+        }
+    }
+    repositories {
+        maven {
+            def version;
+            if ("unspecified".equals(project.version)) {
+                version = parent.version
+            } else {
+                version = project.version
+            }
+            if (version.endsWith('-SNAPSHOT')) {
+                url = REPOSITORY_SNAPSHOT_URL
+            } else {
+                url = REPOSITORY_RELEASE_URL
+            }
+            credentials {
+                username 'publicaccount'
+                password 'publicaccount@2022'
+            }
+        }
+    }
+}
+

+ 81 - 0
version.gradle

@@ -0,0 +1,81 @@
+ext{
+    //spring
+    springBootVersion = '2.7.0'
+    springCloudVersion = '2021.0.3'
+    springCloudAlibabaVersion = '2021.1'
+    gradleManagePluginVersion = '1.0.12.RELEASE'
+
+    springSecurityVersion = '5.7.1'
+    springSecurityOauth2Version = '2.5.2.RELEASE'
+    springSecurityJwtVersion = '1.1.1.RELEASE'
+    springFoxVersion = '3.0.0'
+    nimbusJoseJwtVersion = '9.23'
+    nacosAlibabaVersion='1.4.4'
+
+    //依赖包
+    slf4jApiVersion = '1.7.36'
+    knife4jVersion = '3.0.3'
+    javaxServletVersion = '4.0.1'
+    lombokVersion = '1.18.24'
+    hibernateValidatorVersion = '6.2.3.Final'
+    commLang3Version = '3.12.0'
+    commonsIoVersion = '2.11.0'
+    commonsCompressVersion = '1.21'
+    commonsCodecVersion = '1.15'
+
+    nacosClientVersion = '2.0.3'
+    threadLocalVersion='2.12.6'
+
+    collections4Version='4.4'
+    redissonVersion='3.17.3'
+    hutoolVersion='5.8.3'
+    swaggerAnnotationVersion = '1.6.3'
+    mybatisPlusVersion = '3.5.2'
+
+    beanUtilsVersion = '1.9.4'
+    pinyin4jVersion = '7.2.2'
+    reflectasmVersion = '1.11.9'
+    ip2regionVersion = '1.0.2'
+    thumbnailatorVersion = '0.4.14'
+    feignCoreVersion = '11.8'
+    commonsPool2Version = '2.11.1'
+    httpclientVersion = '4.5.13'
+    aspectjweaverVersion = '1.9.9.1'
+    caffeineVersion= '3.1.0'
+    easyCaptchaVersion = '1.6.2'
+    jasyptSpringBootVersion = '3.0.4'
+
+    guavaVersion = '31.1-jre'
+    gsonVersion = '2.9.0'
+    //cec框架相关包
+    cecdhcFwkUtilsVersion = '1.0.4-SNAPSHOT'
+    cecdhcFwkCommsVersion = '1.0.4-SNAPSHOT'
+    cecdhcKnife4jStarterVersion= '1.0.4-SNAPSHOT'
+    cecdhcWebStarterVersion= '1.0.4-SNAPSHOT'
+    cecdhcLogStarterVersion= '1.0.4-SNAPSHOT'
+    cecdhcRedisStarterVersion= '1.0.4-SNAPSHOT'
+    cecdhcShiroStarterVersion= '1.0.4-SNAPSHOT'
+    cecdhcNacosStarterVersion= '1.0.4-SNAPSHOT'
+    cecdhcMybatisStarterVersion= '1.0.4-SNAPSHOT'
+    cecdhcFeignStarterVersion= '1.0.4-SNAPSHOT'
+    cecdhcDingdingStarterVersion= '1.0.4-SNAPSHOT'
+    cecdhSentinelStarterVersion= '1.0.4-SNAPSHOT'
+    cecdhcMinioStarterVersion= '1.0.4-SNAPSHOT'
+
+    dingtalkVersion='2.0.0'
+    securityLdapVersion='5.6.1'
+    okhttpVersion='4.10.0'
+    minioVersion='8.4.1'
+
+    mysqlVersion = '8.0.29'
+    oracleVersion='21.4.0.0.1'
+    sqljdbcVersion='4.0'
+    postgresqlVersion='42.3.1'
+    db2Version='11.1'
+    jtdsVersion='1.3.1'
+
+    shiroVersion='1.9.1'
+    sessionDataRedisVersion='2.7.0'
+    jjwtVersion='0.11.5'
+    javaJwtVersion='3.19.2'
+}