Gradle多模块

Gradle目录结构

项目名称
├──build.gradle     //全局构建脚本文件,主要的构建配置都在这里写
├──settings.gradle  //全局项目配置,指明根项目名字和引入的 module
│
├──common     ---子模块1目录
│   └──build.gradle //子模块1配置
│
├──mian       ---子模块2目录
│   └──build.gradle //子模块2配置
│
├──gradle    
│ └──wrapper    
│   ├── gradle-wrapper.jar 
│   └── gradle-wrapper.properties  
├──gradlew   
└──gradlew.bat 

全局 settings.gradle 项目配置

pluginManagement {
    repositories {
        gradlePluginPortal()
    }
}


rootProject.name = '项目名称'
include 'common' 
include 'rest'
(或 rootProject.name = '项目名称' include 'common', 'main')  

全局 build.gradle 构建脚本文件,可以定义全局公用的构建配置,以Spring Boot项目配置示例:

buildscript {
    ext {
        springDependencyPluginVersion = '1.0.7.RELEASE'
    }
    repositories {
        maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
        jcenter { url "http://jcenter.bintray.com/"}
    }
    dependencies {
        classpath "io.spring.gradle:dependency-management-plugin:${springDependencyPluginVersion}"
    }
}

//声明插件
plugins {
}

//声明 group
group '组名'
//声明 version
version '版本'

ext {
}

subprojects {
    apply plugin: 'io.spring.dependency-management'
    apply plugin: 'java'

    sourceCompatibility = '1.8'
    targetCompatibility = '1.8'

    configurations {
        compileOnly {
            extendsFrom annotationProcessor
        }
    }

    [javadoc, compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

    compileJava {
        options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
    }

    repositories {
        mavenLocal()
        maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
        jcenter { url "http://jcenter.bintray.com/" }
        // mavenCentral()
    }

    dependencies {
        compile "com.google.guava:guava:${guavaVersion}"
        compile group: 'com.github.briandilley.jsonrpc4j', name: 'jsonrpc4j', version: '1.5.3'
    }

    dependencyManagement {
        imports {
            mavenBom "org.springframework:spring-framework-bom:${springVersion}"
        }
    }
}

子模块 build.gradle 配置

plugins {
    id 'org.springframework.boot' version '2.1.3.RELEASE'
}

ext {
    druidVersion = '1.1.14'
    pagehelperVersion = '5.1.8'
}

dependencies {
    // 依赖其他子模块
    compile project(':common')

    // 配置该项目特有的依赖
    implementation 'XXX'

    compileOnly

    runtime

    runtimeOnly

    annotationProcessor

    testImplementation
}

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(Gradle多模块)