Jak generować klasy z WSDL i XSD za pomocą gradle, odpowiednik maven-jaxb2-plugin

Chcę przełączyć mój plik budowania Maven2 na gradle. Generowanie klas java z WSDL + XSDs za pomocą gradle wydaje się nie być udokumentowane dalej nie ma do tego pluginu gradle. Używam poniższej konfiguracji z maven i szukam odpowiednika dla gradle.

<!-- plugin for generating the classes from the WSDL+XSD -->
<plugin>
  <groupId>org.jvnet.jaxb2.maven2</groupId>
  <artifactId>maven-jaxb2-plugin</artifactId>
  <version>0.7.3</version>
  <executions>
    <execution>
      <id>app1-stub-generation</id>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <schemaDirectory>${project.build.directory}/wsdl/app1</schemaDirectory>
        <schemaIncludes>
          <include>*.xsd</include>
        </schemaIncludes>
        <generatePackage>org.app1.ws.generated</generatePackage>
        <generateDirectory>${project.build.directory}/generated-sources/app1</generateDirectory>
        <strict>true</strict>
      </configuration>
    </execution>
    <execution>
      <id>app2-v1-stub-generation</id>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
        <schemaIncludes>
          <include>v1/*.xsd</include>
        </schemaIncludes>
        <generatePackage>org.app2.ws.generated.v1</generatePackage>
        <generateDirectory>${project.build.directory}/generated-sources/v1</generateDirectory>
        <strict>true</strict>
      </configuration>
    </execution>
    <execution>
      <id>app2-v2-stub-generation</id>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
        <schemaIncludes>
          <include>v2/*.xsd</include>
        </schemaIncludes>
        <generatePackage>org.app2.ws.generated.v2</generatePackage>
        <generateDirectory>${project.build.directory}/generated-sources/v2</generateDirectory>
        <strict>true</strict>
      </configuration>
    </execution>
  </executions>
</plugin> 
Author: Cengiz, 2011-11-16

3 answers

Rozwiązałem to...

configurations {
    jaxb
}

dependencies {
    jaxb group: 'com.sun.xml.bind', name: 'jaxb-xjc', version: '2.2.4-1'
}

task jaxb () {
    // output directory
    jaxbTargetDir = file( "${buildDir}/generated-sources" )
    jaxbTargetDirV19 = file( jaxbTargetDir.path + '/v19' )
    jaxbTargetDirV110 = file( jaxbTargetDir.path + '/v110' )
    jaxbTargetDirOtherWs = file( jaxbTargetDir.path + '/otherWs' )

    // perform actions
    doLast {
        jaxbTargetDirV19.mkdirs()
        jaxbTargetDirV110.mkdirs()
        jaxbTargetDirOtherWs.mkdirs()

        ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask', classpath: configurations.jaxb.asPath)
        ant.jaxbTargetDirV19 = jaxbTargetDirV19
        ant.jaxbTargetDirV110 = jaxbTargetDirV110
        ant.jaxbTargetDirOtherWs = jaxbTargetDirOtherWs

        // My-Webservice v1.10
        ant.xjc(
                destdir: '${jaxbTargetDirV110}',
                package: 'mypackage.ws.generated.v110',
                schema: 'src/main/resources/wsdl/v1.10/MyServiceSchema.xsd'
        )

        // My-Webservice v1.9
        ant.xjc(
                destdir: '${jaxbTargetDirV19}',
                package: 'mypackage.ws.generated.v19',
                schema: 'src/main/resources/wsdl/v1.9/MyServiceSchema.xsd'
        )

        // OtherWs-Webservice
        ant.xjc(
                destdir: '${jaxbTargetDirOtherWs}',
                package: 'mypackage.otherws.generated',
                schema: 'src/main/resources/wsdl/OtherWsServiceSchema.xsd'
        )
    }
}
compileJava.dependsOn jaxb
 23
Author: Cengiz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-11-20 20:08:35

Jeśli nie możesz znaleźć wtyczki Gradle dla konkretnej potrzeby (i nie chcesz pisać własnej wtyczki), zwróć uwagę na zadanie Ant. Oto jeden dla JAXB: Xjc Ant Task .

Każde zadanie Ant może być użyte jako-is Z Gradle (zobacz używanie Ant z Gradle). W przyszłości Gradle będzie również wspierać wykonywanie wtyczek Maven.

 14
Author: Peter Niederwieser,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-11-16 21:25:50

Użyj wtyczki w sposób opisany tutaj: https://github.com/nilsmagnus/wsdl2java

 4
Author: nilsmagnus,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-09-18 19:28:33