Home > Mobile >  Maven To Gradle - Conversion
Maven To Gradle - Conversion

Time:07-21

I am trying to convert an old maven to gradle. Below is the maven block I am trying to convert to gradle equivalent.

        <plugins>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.13.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <generateDirectory>${project.basedir}/target/generated-sources/twg</generateDirectory>
                    <schemaDirectory>${project.basedir}/src/main/resources</schemaDirectory>
                    <schemaIncludes>
                        <include>TWG.wsdl</include>
                    </schemaIncludes>
                </configuration>
            </plugin>
        </plugins>

I tried something like this below

task generateJavaClasses {
    System.setProperty('javax.xml.accessExternalSchema', 'all')
    def jaxbTargetDir = file("src/main/java/")
    doLast {
        jaxbTargetDir.mkdirs()
        ant.taskdef(
                name: 'xjc',
                classname: 'com.sun.tools.xjc.XJCTask',
                classpath: configurations.jaxb.asPath
        )
        ant.jaxbTargetDir = jaxbTargetDir
        ant.xjc(
                destdir: '${jaxbTargetDir}',
                package: 'newjavaFromWsdl',
                schema: 'src/main/resources/TWG.wsdl',
                language: 'WSDL'
        )
    }
}

added the jaxb dependency like

dependencies {
implementation 'com.sun.xml.bind:jaxb-xjc:4.0.0'
}

but not working actually, what am i doing wrong here

CodePudding user response:

There was no issue with the script, but in Gradle, the dependency i used was wrong.

it should be like

configurations {
    jaxb
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web:2.7.1'
    jaxb(
            'com.sun.xml.bind:jaxb-core:3.0.2',
            'com.sun.xml.bind:jaxb-xjc:2.3.6',
            'com.sun.xml.bind:jaxb-impl:2.3.6'
    )
}
  • Related