I’m making the initial leap from Maven to Gradle. Our project is a large, multi-module project, and I created the initial build.gradle files using gradle init. No, I’m going through each module and adding code to replace maven plugins. In one project, we’re using Apache XMLBeans to generate java classes from a schema file. I have this working correctly, but I have a question on how to invoke it. Here is the code in question:
description = 'SPI Generated Code for AMP'
configurations {
xmlbeans
}
dependencies {
xmlbeans 'org.apache.xmlbeans:xmlbeans:2.6.0'
// todo: update with version property
}
task compileBeans {
ant.taskdef(name:'xmlbean', classname: 'org.apache.xmlbeans.impl.tool.XMLBean', classpath: configurations.xmlbeans.asPath)
ant.xmlbean(
schema: 'src/main/resources/xsd/schema.xsd',
classgendir: "${buildDir}/generated-classes/xmlbeans",
srcgendir: "${buildDir}/generated-sources/xmlbeans",
//
destfile: "${buildDir}/libs/${project.name}-${project.version}.jar",
// this is replace in the jar task with the 'from' line
classpath: configurations.xmlbeans.asPath,
memoryInitialSize: '50m',
memoryMaximumSize: '512m')
}
task jar(dependsOn: compileBeans, type: Jar, overwrite: true) {
println 'running custom jar task'
from "${buildDir}/generated-classes/xmlbeans"
}
When I run gradle jar, things work as I expect. However, if i run gradle build, the standard Jar task runs and creates empty jars for me. My assumption is that I will be running gradle build on the root project to build from the groud up - and my project will be missing this dependency. How do I ensure that my overwritten task is run?