-
Notifications
You must be signed in to change notification settings - Fork 10
/
jaxb.gradle
63 lines (42 loc) · 1.65 KB
/
jaxb.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
apply plugin: 'java'
import org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency
final String JAXB_CONFIGURATION_NAME = "jaxb"
project.ext { jaxbVersion = '2.2.7' }
ConfigurationContainer configurations = project.configurations
configurations.create(JAXB_CONFIGURATION_NAME).
setVisible(false).
extendsFrom(configurations.getByName(JavaPlugin.COMPILE_CONFIGURATION_NAME)).
setDescription("JAXB Compile")
ExternalModuleDependency dependency
dependency = new DefaultExternalModuleDependency("com.sun.xml.bind", "jaxb-xjc", project.ext.jaxbVersion)
dependency.setTransitive(false)
project.configurations.getByName(JAXB_CONFIGURATION_NAME).dependencies.add(dependency)
dependency = new DefaultExternalModuleDependency("com.sun.xml.bind", "jaxb-core", project.ext.jaxbVersion)
dependency.setTransitive(false)
project.configurations.getByName(JAXB_CONFIGURATION_NAME).dependencies.add(dependency)
class GenerateJaxb extends org.gradle.api.internal.ConventionTask {
@Input
String jaxbPackage
@InputFile
File schema
@Input
Boolean dtd
@OutputDirectory
File outputDir
@org.gradle.api.tasks.TaskAction
void generateJaxb() {
println("Generating JAXB: ")
println(" jaxbPackage: " + jaxbPackage)
println(" schema: " + schema.absolutePath)
println(" dtd: " + dtd)
println(" outputDir: " + outputDir)
outputDir.mkdirs()
ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJC2Task', classpath: project.configurations.jaxb.asPath)
ant.xjc(destdir: outputDir, package: jaxbPackage, schema: schema.absolutePath) {
if (dtd) {
arg(value: '-dtd')
}
}
}
}
project.ext.generateJaxbType = GenerateJaxb.class