0

I have this project structure:

-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

It is simple of my root settings.gradle:

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

It is my root project 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'
}

And in each subProject, I have build.gradle file with these plugins:

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'

I have duplicate plugins and spring-boot dependency in each subModule and I want to move it to a common(root) file. But I don't understand how can I do it.

ip696
  • 6,574
  • 12
  • 65
  • 128

1 Answers1

0

In the root build.gradle file you can apply common plugins or other configurations like common tasks, sourceCompatibility & targetCompatibility, manifest info, test configs, etc.. using the subprojects block as shown below.

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
}