Hi everyone,
I have a Gradle task in which I have declared and invoked an Ant task.
If I launch the gradle task(named “jaxb”) from command line it works correctly, but it is always executed, even if I launch another task such as “gradle jar”,“gradle compileJava” or “gradle build”.
Is there any way to avoid this?
My build.gradle file following,
Thanks in advance
Paolo
apply plugin: 'java'
group = 'it.ipzs.ws'
version = '2.1.1'
targetCompatibility = '1.5'
repositories {
jcenter()
mavenLocal()
}
configurations{
xjcConf
}
dependencies {
xjcConf 'org.glassfish.jaxb:jaxb-xjc:2.2.11'
xjcConf 'org.glassfish.jaxb:jaxb-runtime:2.2.11'
xjcConf 'org.jvnet.jaxb2_commons:jaxb2-basics-ant:0.6.5'
xjcConf 'org.jvnet.jaxb2_commons:jaxb2-basics:0.6.4'
xjcConf 'org.jvnet.jaxb2_commons:jaxb2-basics-annotate:0.6.4'
}
task jaxb {
ant.taskdef(
name: 'antXjc',
classname: 'org.jvnet.jaxb2_commons.xjc.XJC2Task',
classpath: configurations.xjcConf.asPath
)
File schemaDir = file('resources/it/ipzs/ws/xml/schema')
File bindingDir = file('resources/it/ipzs/ws/xml/binding')
FileCollection schemaFiles = files { schemaDir.listFiles() }
FileCollection bindingFiles = files { bindingDir.listFiles() }
schemaFiles.each {
String schemaName = it.name
String schemaNamePrefix = (schemaName =~ /^(\w+)\./)[0][1]
File bFile = bindingFiles.find{it.name.startsWith(schemaNamePrefix)}
String bindingName = bFile.name
print "Processing file $schemaName..."
copy {
from "resources/it/ipzs/ws/xml/schema/$schemaName"
into "resources/it/ipzs/ws/temp/schema"
}
copy {
from "resources/it/ipzs/ws/xml/binding/$bindingName"
into "resources/it/ipzs/ws/temp/binding"
}
ant.antXjc(
destdir: "src",
package: 'it.ipzs.ws.generated',
schema: "resources/it/ipzs/ws/temp/schema/$schemaName",
binding: "resources/it/ipzs/ws/temp/binding/$bindingName",
extension: 'true'){
arg(value: "-Xinheritance")
}
delete("resources/it/ipzs/ws/temp/schema/$schemaName")
delete("resources/it/ipzs/ws/temp/binding/$bindingName")
println "...Done!"
}
delete("resources/it/ipzs/ws/temp")
}
jar {
manifest {
attributes 'Implementation-Title' : 'gestionelotti-ws',
'Implementation-Version' : version
}
}
sourceSets {
main {
java {
srcDir 'src'
}
resources {
srcDir 'resources'
}
}
}
compileJava {
targetCompatibility = '1.5'
}