java - schemagen gradle build error -
i trying migrate existing maven project gradle build. in maven project using jaxb2-maven-plugin
generate xsd(schemagen)/classes(xjc). wanted same functionality in gradle. have few classes jaxb annotation not how exclude files not needed. when below error.
error:
:createschematargetdir up-to-date :schemagen [ant:schemagen] error: org.gradle.person not have no-arg default constructor. [ant:schemagen] problem related following location: [ant:schemagen] @ org.gradle.person(person.java:5) [ant:schemagen] 1 error :schemagen failed failure: build failed exception. * where: build file 'e:\gradle-schemagen\build.gradle' line: 31 * went wrong: execution failed task ':schemagen'. > schema generation failed
build.gradle
apply plugin: 'java' apply plugin: 'eclipse' sourcecompatibility = 1.6 version = '1.0' schematargetdir = new file('build/generated-schema') configurations { jaxb } jar { manifest { attributes 'implementation-title': 'gradle quickstart', 'implementation-version': version } } repositories { mavencentral() } task createschematargetdir () { schematargetdir.mkdirs() } task schemagen (dependson: createschematargetdir) { dolast { ant.taskdef(name: 'schemagen', classname: 'com.sun.tools.jxc.schemagentask', classpath: configurations.jaxb.aspath) ant.schemagen(srcdir: new file('src/main/java'), destdir: schematargetdir, includeantruntime:'false') { exclude (name:'person.java') } } } test { systemproperties 'property': 'value' } uploadarchives { repositories { flatdir { dirs 'repos' } } } dependencies { compile group: 'commons-collections', name: 'commons-collections', version: '3.2' testcompile group: 'junit', name: 'junit', version: '4.+' jaxb group: 'com.sun.xml.bind', name: 'jaxb-xjc', version: '2.1.6' }
book.java
package org.gradle; import javax.xml.bind.annotation.xmlelement; import javax.xml.bind.annotation.xmlrootelement; import javax.xml.bind.annotation.xmltype; @xmlrootelement(name = "book") // if want can define order in fields written // optional @xmltype(proporder = { "author", "name", "publisher", "isbn" }) public class book { private string name; private string author; private string publisher; private string isbn; // if variable name, e.g. "name", can change // name xml-output: @xmlelement(name = "title") public string getname() { return name; } public void setname(string name) { this.name = name; } public string getauthor() { return author; } public void setauthor(string author) { this.author = author; } public string getpublisher() { return publisher; } public void setpublisher(string publisher) { this.publisher = publisher; } public string getisbn() { return isbn; } public void setisbn(string isbn) { this.isbn = isbn; } }
person.java
package org.gradle; import org.apache.commons.collections.list.growthlist; public class person { private final string name; public person(string name) { this.name = name; new growthlist(); } public string getname() { return name; } }
thank in advance.
i had few classpath issue, solved below changes.
ant.schemagen(srcdir: new file('src/main/java'), destdir: schematargetdir, includeantruntime:'false') { classpath { pathelement(path: configurations.jaxb.aspath ) } } dependencies { compile group: 'commons-collections', name: 'commons-collections', version: '3.2' testcompile group: 'junit', name: 'junit', version: '4.+' jaxb ( 'com.sun.xml.bind:jaxb-xjc:2.1.6', 'org.apache.avro:avro-tools:1.7.5', 'org.apache.avro:avro:1.7.5' ) }
Comments
Post a Comment