vendredi 30 juin 2017

Generate classes with gradle and jaxb for tests with different configuration

I'm using

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

http://ift.tt/2tt8fLu

gradle plugin and this configuration:

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

but for tests I want to add more arguments to xjc. Maven solves this with help of executions

               <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>

But how to solve it in gradle? I want as result 2 sets of classes in different folders - one for production code and one for tests (with additional jaxb plugins enabled)

Aucun commentaire:

Enregistrer un commentaire