Search code examples
javagradlexsdapache-axisxmlbeans

how to generate java class from xsd by using xmlbeans in gradle


I am new to gradle. In my project, i have xsd files and i would like to generate java classes from that xsd (using xmlbeans only). How to do that in gradle.

I am using axis2 1.6.1, gradle, xmlbean 2.3.0` (JAXB is not an option in my current project).


Solution

  • As far as I know, you can use the "xmlbeansPlugin" for this. Can't say now, whether it's possible to change the xmlbean's version to the older one.

    All you need is to apply the plugin to your build script:

    apply from: 'https://raw.github.com/rartavia/gradle-plugins/master/xmlbeansPlugin/xmlbeans.gradle'
    

    Then declare xmlbeans configuration and it's dependency

    configurations {
        xmlbeans
    }
    
    dependencies {
        xmlbeans 'org.apache.xmlbeans:xmlbeans:2.5.0'
    }
    

    After that you have to specify the xsd files location

    sourceSets {
        schemas {
                srcDir = 'src/main/schemas'
        }
    }
    

    And now you can call compileXmlSchemas task to generate classes