6.8.3 How to share repo/plugins/config on composite build projects?

We run a mono-repo of composite builds so it scales very well (ie. opening 1 project does not bring in all projects and only brings in the stuff it depends on).

Each project is duplicating code if you read the comment ‘DUPLICATED’

plugins {
    id 'java-library'
    id 'checkstyle'   //DUPLICATED
}

apply from: '../../config/global.gradle' //Brings in common deps across whole repo to prevent jar hell between teams

group 'com.orderlyhealth.util'

repositories {.   //DUPLICATED
    mavenCentral()  //DUPLICATED
    maven { url uri('/tmp/myRepo/') } // DUPLICATED
}

dependencies {
    implementation deps['slf4j']
}

checkstyle { //DUPICATED
    configFile = rootProject.file('../../config/checkstyle.xml') //DUPLICATED
    ignoreFailures = false //DUPLICATED
}

QUESTION 1: How can we not duplicate this code?
QUESTION 2: How can we not duplicate this code but allow overriding the global configuration?

thanks,
Dean

Try 1 is with global.config that I want to re-use across all projects in a composite build →

plugins {
    id 'checkstyle'
}

repositories {
    mavenCentral()
    maven { url uri('/tmp/myRepo/') } // For testing locally
}

checkstyle {
    configFile = rootProject.file('../../config/checkstyle.xml')
}

And the project build.gradle file that uses it →

plugins {
    id 'java-library'
}

apply from: '../../config/global.gradle'

group 'com.orderlyhealth.util'

dependencies {
    api 'org.slf4j:slf4j-api'
    implementation 'ch.qos.logback:logback-classic'
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            pom {
                description = 'Webpieces logging library'
            }
        }
    }
}

ERROR:

startup failed:
script ‘/Users/dean/workspace/webpieces/config/global.gradle’: 1: Only Project and Settings build scripts can contain plugins {} blocks

See Using Gradle Plugins for information on the plugins {} block

Try #2 moving id ‘checkstyle’ into the build.gradle and out of global.gradle is a step in the right direction but I am not sure if the repository section is used but the checkstyle one definitely is being used.