1. 安装

  安装gradle,配置环境变量,查看版本

 

 

2. 在IDEA中创建gradle聚合项目配置

  build.gradle文件配置

// 配置allprojects后就可以在所有的子项目中使用父项目中的模块
allprojects {
    apply plugin: 'java'

    group 'com.lewang'
    version '1.0-SNAPSHOT'

    sourceCompatibility = 1.8

    repositories {
        mavenLocal()
        mavenCentral()
    }

    dependencies {
        testCompile group: 'junit', name: 'junit', version: '4.12'
        implementation group: 'org.springframework', name: 'spring-context', version: '5.3.19'
    }

    task"create-dirs" << {

        sourceSets*.java.srcDirs*.each {

            it.mkdirs()

        }

        sourceSets*.resources.srcDirs*.each {

            it.mkdirs()

        }
    }
}

 

  父项目settings.gradle中可以看到子项目

rootProject.name = 'gradle-parent'
include 'gradle-dao'
include 'gradle-service'
include 'gradle-web'
include 'gradle-webapp'

 

  父项目中已经有的就可以不用在子项目中再次配置了

  需要在子项目中引用的需要单独配置

  gradle-webapp的build.gradle文件配置
//配置子项目是web项目
apply plugin: 'war'

//可以在子模块中引用其他子模块
dependencies {
    compile project(":gradle-service")
}

 

posted on 2022-04-23 11:24  homle  阅读(56)  评论(0编辑  收藏  举报