从子项目中提取插件的副本到根 gradle 配置



我有这个项目结构:

-root-project
 -settings.gradle
 -build.gradle
 -subProjectA(spring-boot)
  -build.gradle
 -subprojectB(spring-boot)
  -build.gradle
 -subprojectC(spring-boot)
  -build.gradle
 -commonProject(java library)
  -build.gradle

我的根设置很简单.gradle:

rootProject.name = 'root-project'
include 'subProjectA'
include 'subprojectB'
include 'subprojectC'
include 'commonProject'

这是我的根项目 build.gradle:

group = 'my.domain'
version = '0.0.1-SNAPSHOT'
ext {
    springBootVersion = '2.1.3.RELEASE'
    cxfVersion = '3.2.7'
    uuidGeneratorVersion = '3.1.5'
    commonLang3Version = '3.7'
    encacheVersion = '2.6.11'
    logstashVersion = '5.2'
}

在每个子项目中,我都有build.gradle包含这些插件的文件:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'eclipse'

我在每个subModule中都有重复的插件和spring-boot依赖项,我想将其移动到一个通用(根(文件中。但我不明白我该怎么做。

在根build.gradle文件中,您可以使用subprojects块应用常用插件或其他配置,如常见任务、sourceCompatibility & targetCompatibility 、manifest info、test configs 等。

subprojects {
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'
    apply plugin: 'idea'
    apply plugin: 'java'
    apply plugin: 'eclipse'
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    jar {
        manifest {
            attributes (
                'Built-By'       : System.properties['user.name'],
                'Build-Timestamp': new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()),
                'Created-By'     : "Gradle ${gradle.gradleVersion}",
                'Build-Jdk'      : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
                'Build-OS'       : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}"
            )
        }
    }
   // Other Configs
}

最新更新