项目结构
example
  ├─.gradle
  ├─.idea
  ├─example-client
  │  ├─src
  │  └─build.gradle
  ├─example-model
  │  ├─src
  │  └─build.gradle
  ├─example-server
  │  ├─src
  │  └─build.gradle
  ├─example-utils
  │  ├─src
  │  └─build.gradle
  ├─build.gradle
  ├─example.iml
  └─settings.gradle
example/settings.gradle 文件
rootProject.name = 'example'
include 'example-server'
include 'example-model'
include 'example-utils'
include 'example-client'
example/build.gradle 文件
// 设置Maven仓库地址
def LocalMavenRepository = 'file://D:/ToolsSoftware/Maven/.m2/repository'
def RemoteMavenRepository_1 = 'http://maven.aliyun.com/nexus/content/groups/public/'
def RemoteMavenRepository_2 = 'http://maven.aliyun.com/nexus/content/repositories/jcenter/'
def PrivateMavenRepository = 'http://39.108.68.132:8081/repository/'
def PrivateMavenRepositoryUsername = '用户名'
def PrivateMavenRepositoryPassword = '密码'

// 设置Gradle脚本自身的执行环境配置
buildscript {
    ext {
        springBootVersion = '2.0.4.RELEASE'
    }
    repositories {
        maven { url '${LocalMavenRepository}' }
        maven { url '${RemoteMavenRepository_1}' }
        maven { url '${RemoteMavenRepository_2}' }
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

// 所有的项目配置
allprojects {
    // 设置Maven仓库
    repositories {
        maven { url LocalMavenRepository }
        maven { url RemoteMavenRepository_1 }
        maven { url RemoteMavenRepository_2 }
        mavenCentral()
    }
}

// 所有子项目的配置
subprojects {
    // 使用Gradle插件
    apply plugin: 'java'
    apply plugin: 'io.spring.dependency-management'
    apply plugin: 'maven-publish'

    // 设置项目属性
    group 'org.learn'
    version '1.0-SNAPSHOT'
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    [compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'

    // 设置全局依赖
    dependencyManagement {
        // 全局依赖版本设置,参考 https://github.com/spring-gradle-plugins/dependency-management-plugin
        imports {
            mavenBom 'org.springframework.boot:spring-boot-starter-parent:2.0.4.RELEASE'
            mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Finchley.SR1'
        }
        dependencies {
            dependency 'org.springframework.cloud:spring-cloud-starter-eureka:1.4.5.RELEASE'
            dependency 'org.apache.commons:commons-text:1.1'
            dependency 'com.github.cage:cage:1.0'
            dependency 'org.apache.commons:commons-email:1.5'
            dependency 'io.springfox:springfox-swagger2:2.7.0'
            dependency 'io.springfox:springfox-swagger-ui:2.7.0'
            dependency 'javax.persistence:persistence-api:1.0.2'
            dependency 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
            dependency 'com.github.pagehelper:pagehelper-spring-boot-starter:1.2.1'
        }
    }
    dependencies {
        compileOnly('org.projectlombok:lombok:1.18.2')
        compile('org.springframework.boot:spring-boot-starter-web')
        testCompile('org.springframework.boot:spring-boot-starter-test')
    }

    // 打包源码Jar
    task sourcesJar(type: Jar) {
        from sourceSets.main.allJava
        classifier 'sources'
    }
    // 打包JavaDoc
    task javadocJar(type: Jar) {
        from javadoc
        classifier = 'javadoc'
    }

    // 发布到Maven仓库配置
    publishing {
        repositories {
            maven {
                name = 'local'
                url = LocalMavenRepository
            }
            maven {
                name = 'nexus'
                def releasesRepoUrl = "${PrivateMavenRepository}maven-releases/"
                def snapshotsRepoUrl = "${PrivateMavenRepository}maven-snapshots/"
                url = version.toUpperCase().endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
                credentials {
                    username = PrivateMavenRepositoryUsername
                    password = PrivateMavenRepositoryPassword
                }
            }
        }
        publications {
            mavenJava(MavenPublication) {
                from components.java
                //配置上传源码
                artifact sourcesJar
                artifact javadocJar
            }
        }
    }
}
example/example-client/build.gradle 文件
dependencies {
    compile project(':example-model')
    compile('com.github.pagehelper:pagehelper-spring-boot-starter')
    compile('org.springframework.cloud:spring-cloud-starter-eureka')
}
example/example-utils/build.gradle 文件
dependencies {
    compile('org.apache.commons:commons-lang3')
    compile('org.apache.commons:commons-text')
    compile('commons-codec:commons-codec')
    compile('org.ehcache:ehcache')
    compile('com.github.cage:cage')
    compile('org.apache.commons:commons-email')
}
example/example-model/build.gradle 文件
dependencies {
    compile project(':example-utils')
    compile('io.springfox:springfox-swagger2')
    compile('javax.persistence:persistence-api')
    compile('com.fasterxml.jackson.core:jackson-annotations')
}
example/example-server/build.gradle 文件
apply plugin: 'org.springframework.boot'

dependencies {
    compile project(':example-model')
    compile project(':example-utils')
    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.springframework.cloud:spring-cloud-starter-config')
    compile('org.springframework.cloud:spring-cloud-starter-eureka')
    compile('io.springfox:springfox-swagger2')
    compile('io.springfox:springfox-swagger-ui')
}
文档更新时间: 2019-07-04 12:52   作者:lizw