Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Gradle Configurations

DZone's Guide to

Gradle Configurations

Alex Jacinto reviews how to generate source code for all of your projects using Gradle, making software development easy.

· DevOps Zone ·
Free Resource

Easily enforce open source policies in real time and reduce MTTRs from six weeks to six seconds with the Sonatype Nexus Platform. See for yourself - Free Vulnerability Scanner. 

One of the best features of Gradle is its ability to setup scaffolding for projects with common attributes.  For example, you can simply tell Gradle to generate source code for every project with a schema directory in proper location.
configure(xsdProjects()) {
    apply from: "$rootDir/gradle/jaxb.gradle"
}
def xsdProjects() {
        ext.schemaProjects = [] as Set
ext.schemaProjects.addAll subprojects.findAll { Project aProject ->
File xsdDir = new File(aProject.projectDir.path + '/src/main/resources/xsd')
xsdDir.exists()
}
ext.schemaProjects
}
Imagine working with a large code base with multiple sub projects where a handful you have to generate code from schema and few of them you have to generate from wsdl.  You can then isolate these configurations into separate files and apply them in your main build.gradle.
apply from: ‘gradle/xsd.gradle’

apply from: 'gradle/wsdl.gradle'
This setup will make the build.gradle in your sub-projects to a bare minimum.  At the most, you only need to include the sub-project description, its project dependencies and external dependencies that only apply to each.  
A very important after effect of this is that you are enforcing the conventions of your code base.  You are forcing your coworkers to put their schema and wsdl in a known place because if they don’t, they have to write all the build scripts and customize it.  In summary we are enforcing “DRY” and implementing convention over configuration.

Automate open source governance at scale across the entire software supply chain with the Nexus Platform. Learn more.

Topics:
devops ,gradle ,build

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}