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

Can you release faster without sacrificing quality? See how with our free ebook Strategies for a Successful Test Automation Project and a free trial of Ranorex Studio today!

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.

Get your test automation project off to the right start. Download your free test planning template and a 30-day no-obligation trial of Ranorex Studio today!

Topics:
devops ,gradle ,build

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}