gpt4 book ai didi

java - schemagen gradle 构建错误

转载 作者:行者123 更新时间:2023-11-29 08:53:22 25 4
gpt4 key购买 nike

我正在尝试将现有的 Maven 项目迁移到 gradle 构建。在 Maven 项目中,我使用 jaxb2-maven-plugin 生成 xsd(schemagen)/classes(xjc)。我想在 gradle 中获得相同的功能。我有几个带有 jaxb 注释的类,但有些不是,所以我如何排除不需要的文件。当我执行以下操作时出现错误。

错误:

:createschemaTargetDir UP-TO-DATE
:schemagen
[ant:schemagen] error: org.gradle.Person does not have a no-arg default constructor.
[ant:schemagen] this problem is related to the following location:
[ant:schemagen] at org.gradle.Person(Person.java:5)
[ant:schemagen] 1 error
:schemagen FAILED

FAILURE: Build failed with an exception.

* Where:
Build file 'E:\gradle-schemagen\build.gradle' line: 31

* What went wrong:
Execution failed for 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 you want you can define the order in which the fields are written
// Optional
@XmlType(propOrder = { "author", "name", "publisher", "isbn" })
public class Book {

private String name;
private String author;
private String publisher;
private String isbn;

// If you like the variable name, e.g. "name", you can easily change this
// name for your 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;
}
}

提前谢谢你。

最佳答案

我有几个类路径问题,已通过以下更改解决。

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'
)
}

关于java - schemagen gradle 构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21591636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com