Gradle聚合工程

1、创建完的目录结构

2、创建一个普通的gradle项目gradle-parent

3、选中项目,右键新建一各gradle-dao模块

  创建完后的工程目录如下

4、以同样方式创建gradle-service模块

5、选中项目,右键新建一个gradle-web模块

 创建完成后的工程目录如下

6、删除父工程的src目录

7、修改父工程build.gradle

//声明gradle脚本吱声需要使用的资源
buildscript {
    repositories {
        mavenLocal()
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
        mavenCentral()
    }
    ext {
        springBootVersion = '2.1.2.RELEASE'
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

// 所有模块/项目的通用配置
allprojects {
    //指定编辑器
    apply plugin: 'idea'
    //配置项目信息
    group 'org.glx'
    version '1.0-SNAPSHOT'

}


// 子模块/项目的统一配置
subprojects {
    //指定需要的插件
    apply plugin: 'java'
//    apply plugin: 'org.springframework.boot'
    // 指定JDK版本
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    // 指定编码格式
    [compileJava,compileTestJava,javadoc]*.options*.encoding = 'UTF-8'
    repositories {
        //优先从本地仓库获取
        mavenLocal()
        // 从阿里云或者公司仓库获取
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
        // 从中央仓库获取
        mavenCentral()
    }
    //配置全局依赖版本信息
    ext {
        springBootVersion = "2.1.2.RELEASE"
        mysqlConnectorVersion = "8.0.13"
        mybatisStarterVersion = "1.3.2"
        fastjsonVersion = "1.2.54"
        slf4jVersion = "1.7.16"
        commonsVersion = "3.0"
        junitVersion = "4.12"
    }
    //配置子模块依赖
    dependencies {
        compile("javax.servlet:javax.servlet-api:4.0.1")
        compile("org.springframework.boot:spring-boot-starter-web:$springBootVersion")
        // Mybatis
        compile("org.mybatis.spring.boot:mybatis-spring-boot-starter:$mybatisStarterVersion")
        // Log4j2
        compile("org.springframework.boot:spring-boot-starter-log4j2:$springBootVersion")
        // JDBC Driver
        compile("mysql:mysql-connector-java:$mysqlConnectorVersion")
        // JSON
        compile("com.alibaba:fastjson:$fastjsonVersion")
        // Apache Commons
        compile("org.apache.commons:commons-lang3:3.8.1")

        // 单元测试
        testCompile("org.springframework.boot:spring-boot-starter-test:$springBootVersion")
        testCompile("junit:junit:4.12")
    }
    configurations {
        //移除spring boot 默认logger依赖
        all*.exclude module: 'spring-boot-starter-logging'
    }
}

8、修改gradle-dao模块的build.gradle

plugins {
    id 'java'
}
//配置该子模块持有的依赖
dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}

9、修改gradle-service模块的build.gradle

plugins {
    id 'java'
}

//配置该子模块持有的依赖
dependencies {
    //依赖dao项目
    compile project(":gradle-dao")
    //配置该项目持有的依赖
}

10、修改gradle-web模块的build.gradle

plugins {
    id 'war'
}

dependencies {
    //依赖dao项目
    compile project(":gradle-dao")
    //依赖service项目
    compile project(":gradle-service")
    testImplementation 'junit:junit:4.11'
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值