如何为com.github.bjornvester.xjc 1.8.2配置-no-separate-collection
解决com.github.bjornvester.xjc插件生成独立集合类的问题
要让com.github.bjornvester.xjc 1.8.2插件不再生成独立的集合类,只需在Gradle配置中给XJC添加-no-separate-collections参数(这是XJC的标准参数),具体配置方式如下:
Gradle配置示例
plugins { id 'com.github.bjornvester.xjc' version '1.8.2' } xjc { // 保留你的其他配置,比如指定XSD路径、生成目录等 xjcOptions { // 添加禁用独立集合类的参数 add "-no-separate-collections" } }
参数作用说明
添加该参数后,XJC会直接在对应的主类中使用标准Java集合类型(如List),而不会额外生成类似VendorComponentsType这类专门的集合封装类,和你之前使用com.ewerk.gradle.plugins.jaxb2插件的效果一致。
效果对比
原XSD片段示例
<xs:complexType name="VendorType"> <xs:sequence> <xs:element name="component" type="ComponentType" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType>
未配置参数时生成的代码
会额外生成集合类:
// 多余的集合封装类 public class VendorComponentsType { protected List<ComponentType> component; // getter、setter方法 } public class VendorType { protected VendorComponentsType components; // getter、setter方法 }
配置参数后生成的代码
直接在主类中使用集合:
public class VendorType { protected List<ComponentType> component; // getter、setter方法 }
内容的提问来源于stack exchange,提问作者Surendra
相关产品推荐
相关产品推荐

