Over a million developers have joined DZone.

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

Planning to extract out a few microservices from your monolith? Read this free guide to learn the best practice before you get started.

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')
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.

Learn how to measure the impact of every feature release on performance and customer experience metrics.

devops ,gradle ,build

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}