Over a million developers have joined DZone.

Gradle Configurations

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

· DevOps Zone

The DevOps Zone is brought to you in partnership with Sonatype Nexus. The Nexus Suite helps scale your DevOps delivery with continuous component intelligence integrated into development tools, including Eclipse, IntelliJ, Jenkins, Bamboo, SonarQube and more. Schedule a demo 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.

The DevOps Zone is brought to you in partnership with Sonatype Nexus. Use the Nexus Suite to automate your software supply chain and ensure you're using the highest quality open source components at every step of the development lifecycle. Get Nexus today

Topics:
devops ,gradle ,build

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}