jsonxsdjsonix

jsonix-schema-compiler Maven usage


I have tried to use jsonix-schema-compiler according to https://github.com/highsource/jsonix-schema-compiler/wiki/Maven-Usage but it doesn't work

I have even tried to specify other arguments as follows:

<build>
   <finalName>test-json</finalName>
   <plugins>
     <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>0.13.1</version>

        <executions>
            <execution>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <extension>true</extension>
                    <args>
                        <arg>-Xjsonix</arg>
                        <arg>-generateJsonSchema</arg>                          
                        <arg>-d</arg>
                        <arg>${basedir}/target/generated-sources/</arg>                         
                        <arg>-b</arg>
                        <arg>${basedir}/src/main/resources/xsd/jaxb_bindings.xjb</arg>                  
                        <arg>-p</arg>
                        <arg>CustomerJSON</arg>
                        <arg>-Xjsonix-logLevel</arg>
                        <arg>TRACE</arg>
                        <arg>${basedir}/src/main/resources/xsd/Customer.xsd</arg>
                    </args>
                    <plugins>
                        <plugin>
                            <groupId>org.hisrc.jsonix</groupId>
                            <artifactId>jsonix-schema-compiler</artifactId>
                            <version>${jsonix-schema-compiler.version}</version>
                        </plugin>
                    </plugins>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

but nothing changes and all what I get is [WARNING] No schemas to compile. Skipping XJC execution. as can be seen in the following logs

    C:\test-json>mvn clean install  -Dmaven.test.skip=true
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Module test-json 1.0.0.0
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ test-json ---
    [INFO] Deleting C:\test-json\target
    [INFO]
    [INFO] --- build-helper-maven-plugin:1.9:maven-version (maven-version) @ test-json ---
    [INFO]
    [INFO] --- build-helper-maven-plugin:1.9:parse-version (parse-project-version) @ test-json ---
    [INFO]
    [INFO] --- build-helper-maven-plugin:1.9:timestamp-property (extract-build-year) @ test-json ---
    [INFO]
    [INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-cub3-rules) @ test-json ---
    [INFO]
    [INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-cub3-warnings) @ test-json ---
    [WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireProperty failed with message:
    Property 'cub-distrib-mirror-url' should be defined in your settings.
    [INFO]
    [INFO] --- jacoco-maven-plugin:0.7.4.201502262128:prepare-agent (pre-unit-test) @ test-json ---
    [INFO] argLine set to -javaagent:C:\\Users\\...\\jacoco-ut.exec,append=true
    [INFO]
    [INFO] --- maven-jaxb2-plugin:0.13.1:generate (default) @ test-json ---
    [WARNING] No schemas to compile. Skipping XJC execution.
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test-json ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 4 resources
    [INFO] skip non existing resourceDirectory C:\test-json\target\generated-sources\xjc
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-json ---
    [INFO] No sources to compile
    [INFO]
    [INFO] --- findbugs-maven-plugin:2.5.4:findbugs (findbugs) @ test-json ---
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ test-json ---
    [INFO] Not copying test resources
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test-json ---
    [INFO] Not compiling test sources
    [INFO]
    [INFO] --- maven-surefire-plugin:2.17:test (default-test) @ test-json ---
    [INFO] Tests are skipped.
    [INFO]
    [INFO] --- jacoco-maven-plugin:0.7.4.201502262128:report (post-unit-test) @ test-json ---
    [INFO] Skipping JaCoCo execution due to missing execution data file:C:\test-json\target\coverage-reports\jacoco-ut.exec
    [INFO]
    [INFO] --- maven-jar-plugin:2.5:jar (default-jar) @ test-json ---
    [INFO] Building jar: C:\test-json\target\test-json.jar
    [INFO]
    [INFO] --- maven-site-plugin:3.3:attach-descriptor (attach-descriptor) @ test-json ---
    [INFO]
    [INFO] --- jacoco-maven-plugin:0.7.4.201502262128:prepare-agent (pre-integration-test) @ test-json ---
    [INFO] argLine set to -javaagent:C:\\Users\\...\\jacoco-it.exec,append=true
    [INFO]
    [INFO] >>> maven-pmd-plugin:3.2:check (default) > :pmd @ test-json >>>
    [INFO]
    [INFO] --- maven-pmd-plugin:3.2:pmd (pmd) @ test-json ---
    [INFO]
    [INFO] <<< maven-pmd-plugin:3.2:check (default) < :pmd @ test-json <<<
    [INFO]
    [INFO] --- maven-pmd-plugin:3.2:check (default) @ test-json ---
    [INFO]
    [INFO] >>> maven-pmd-plugin:3.2:cpd-check (check-duplication) > :cpd @ test-json >>>
    [INFO]
    [INFO] --- maven-pmd-plugin:3.2:cpd (cpd) @ test-json ---
    [INFO]
    [INFO] <<< maven-pmd-plugin:3.2:cpd-check (check-duplication) < :cpd @ test-json <<<
    [INFO]
    [INFO] --- maven-pmd-plugin:3.2:cpd-check (check-duplication) @ test-json ---
    [INFO]
    [INFO]
    [INFO] >>> findbugs-maven-plugin:2.5.4:check (findbugs) > :findbugs @ test-json >>>
    [INFO]
    [INFO] --- findbugs-maven-plugin:2.5.4:findbugs (findbugs) @ test-json ---
    [INFO]
    [INFO] <<< findbugs-maven-plugin:2.5.4:check (findbugs) < :findbugs @ test-json <<<
    [INFO]
    [INFO] --- findbugs-maven-plugin:2.5.4:check (findbugs) @ test-json ---
    [INFO]
    [INFO] --- maven-checkstyle-plugin:2.12.1:check (default) @ test-json ---
    [INFO]
    [INFO] --- jacoco-maven-plugin:0.7.4.201502262128:report (post-integration-test) @ test-json ---
    [INFO] Skipping JaCoCo execution due to missing execution data file:C:\test-json\target\coverage-reports\jacoco-it.exec
    [INFO]
    [INFO] --- maven-install-plugin:2.5.1:install (default-install) @ test-json ---
    [INFO] Installing C:\test-json\target\test-json.jar to C:\Users\...\test-json\1.0.0.0\test-json-1.0.0.0.jar
    [INFO] Installing C:\test-json\pom.xml to C:\Users\..\test-json\1.0.0.0\test-json-1.0.0.0.pom
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 5.931 s
    [INFO] Finished at: 2016-04-19T18:16:09+02:00
    [INFO] Final Memory: 38M/444M
    [INFO] ------------------------------------------------------------------------
    C:\test-json>

So what is the good configurations for jsonix-schema-compiler?


Solution

  • You shouldn't "mirror" your command-line XJC/Jsonix Schema Compiler usage in Maven config. It works much more with convention over configuration.

    So just put your schemas and binding files in src/main/resourcesand then just turn on Jsonix XJC plugin with -Xjsonix:

    <build>
       <finalName>test-json</finalName>
       <plugins>
         <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.13.1</version>
    
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <extension>true</extension>
                        <args>
                            <arg>-Xjsonix</arg>
                            <arg>-Xjsonix-generateJsonSchema</arg>                          
                        </args>
                        <plugins>
                            <plugin>
                                <groupId>org.hisrc.jsonix</groupId>
                                <artifactId>jsonix-schema-compiler</artifactId>
                                <version>${jsonix-schema-compiler.version}</version>
                            </plugin>
                        </plugins>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    

    If you actually want to reconfigure source and target directories and so on, check maven-jaxb2-plugin configuration (see the cheat sheet, for instance). Specifically, for the configuration you'll probably need: