build.gradle 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. configurations {
  2. jaxb
  3. }
  4. group = 'ru.sudrf'
  5. version = '0.1'
  6. buildDir = 'target'
  7. apply plugin: 'java'
  8. sourceCompatibility = '1.8'
  9. targetCompatibility = '1.8'
  10. compileJava.options.encoding = 'UTF-8'
  11. tasks.withType(JavaCompile) {
  12. options.encoding = 'UTF-8'
  13. }
  14. repositories {
  15. mavenCentral()
  16. }
  17. sourceSets.main.java.srcDirs "${buildDir}/generated-sources/jaxb"
  18. task genJaxb {
  19. ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
  20. ext.classesDir = "${buildDir}/classes/jaxb"
  21. outputs.dir classesDir
  22. doLast() {
  23. project.ant {
  24. mkdir(dir: sourcesDir)
  25. mkdir(dir: classesDir)
  26. taskdef name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask', classpath: configurations.jaxb.asPath
  27. xjc(destdir: sourcesDir, binding: "${projectDir}/src/main/resources/binding.xml") {
  28. schema(dir: "${projectDir}/src/main/resources/xsd", includes: '**/*.xsd')
  29. arg(value: "-extension")
  30. arg(value: "-encoding")
  31. arg(value: "UTF-8")
  32. produces(dir: sourcesDir, includes: '**/*.java')
  33. }
  34. javac(destdir: classesDir, source: 1.8, target: 1.8, debug: true,
  35. debugLevel: 'lines,vars,source',
  36. includeantruntime: false,
  37. classpath: configurations.jaxb.asPath) {
  38. src(path: sourcesDir)
  39. include(name: '**/*.java')
  40. include(name: '*.java')
  41. }
  42. copy(todir: classesDir) {
  43. fileset(dir: sourcesDir, erroronmissingdir: false) {
  44. exclude(name: '**/*.java')
  45. }
  46. }
  47. }
  48. }
  49. }
  50. dependencies {
  51. compile(files(genJaxb.classesDir).builtBy(genJaxb))
  52. jaxb (
  53. 'com.sun.xml.bind:jaxb-xjc:2.3.9',
  54. 'com.sun.xml.bind:jaxb-impl:2.3.9',
  55. 'org.glassfish.jaxb:jaxb-runtime:2.3.9'
  56. )
  57. }
  58. compileJava.dependsOn 'genJaxb'
  59. jar {
  60. from genJaxb.classesDir
  61. }
  62. java {
  63. withSourcesJar()
  64. }