使用gradle和jaxb为具有不同配置的测试生成类

时间:2017-06-30 12:44:41

标签: testing gradle jaxb xjc

我正在使用

id "com.bmuschko.docker-java-application" version "3.0.7"

https://github.com/rackerlabs/gradle-jaxb-plugin

gradle插件和此配置:

jaxb {
    xsdDir = "${project.projectDir}/src/main/xsd/"
    bindingsDir = "${project.projectDir}/src/main/xsd/"

    xjc {
        taskClassname = "org.jvnet.jaxb2_commons.xjc.XJC2Task"
        args = [
                '-Xfluent-api'
        ]
    }
}

sourceSets.main.java.srcDirs += "${generatedSources}"
compileJava.dependsOn xjc

for tests我想为xjc添加更多参数。并使用常规gradle build运行此新任务(取决于此测试任务)。 Maven在执行的帮助下解决了这个问题

               <plugin>
                    <groupId>org.jvnet.jaxb2.maven2</groupId>
                    <artifactId>maven-jaxb2-plugin</artifactId>
                    <version>0.13.1</version>
                    <executions>
                        <execution>
                            <id>prod</id>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>test</id>
                            <phase>process-test-sources</phase>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                            <configuration>
                                <generateDirectory>target/generated-test-sources/xjc</generateDirectory>
                                <addCompileSourceRoot>false</addCompileSourceRoot>
                                <addTestCompileSourceRoot>true</addTestCompileSourceRoot>
                                <args>
                                    <arg>-Xfluent-api</arg>
                                    <arg>-Xinheritance</arg>
                                    <arg>-Xannotate</arg>
                                    <arg>-Xvalue-constructor</arg>
                                    <arg>-Xequals</arg>
                                    <arg>-XhashCode</arg>
                                    <arg>-XtoString</arg>
                                </args>
                            </configuration>
                        </execution>
                    </executions>
                    <configuration>
                        <schemaDirectory>src/main/xsd</schemaDirectory>
                        <bindingDirectory>src/main/xsd</bindingDirectory>
                        <removeOldOutput>true</removeOldOutput>
                        <extension>true</extension>
                        <verbose>true</verbose>
                        <readOnly>true</readOnly>
                        <args>
                            <arg>-Xfluent-api</arg>
                        </args>
                    </configuration>
                </plugin>

但是如何在gradle中解决它?我希望在不同的文件夹中有2组类 - 一组用于生产代码,另一组用于测试(启用了额外的jaxb插件)。

简单

task tst(type: org.openrepose.gradle.plugins.jaxb.task.JaxbXjc) {

}

需要单独的配置

> No value has been specified for property 'bindings'.
> No value has been specified for property 'episodeDirectory'.
> No value has been specified for property 'generatedFilesDirectory'.
> No value has been specified for property 'schemasDirectory'.
> No value has been specified for property 'xsds'.

与dsl不同。如何重用基于dsl的配置?

0 个答案:

没有答案