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
}

 

 

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章