3

I am trying to use the jsonschema2pojo plugin for generating POJOs based on both schema and json sourceTypes. The configurations are specified per execution. But every time the plugin is reporting "One of sourceDirectory or sourcePaths must be provided". I am able to run it when the configuration is provided at the plugin level ( global ). But then I can only specify one sourceType.

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.jsonschema2pojo</groupId>
                <artifactId>jsonschema2pojo-maven-plugin</artifactId>
                <version>0.5.1</version>
                <executions>
                    <execution>
                        <id>generate-schema</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <outputEncoding>${project.build.sourceEncoding}</outputEncoding>
                            <outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
                            <annotationStyle>jackson2</annotationStyle>
                            <generateBuilders>false</generateBuilders>
                            <initializeCollections>true</initializeCollections>
                            <refFragmentPathDelimiters>#/</refFragmentPathDelimiters>
                            <sourceType>jsonschema</sourceType>
                            <targetPackage>com.company.app.integration.sabre.stub.rest</targetPackage>
                            <sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>generate-json</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <outputEncoding>${project.build.sourceEncoding}</outputEncoding>
                            <outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
                            <annotationStyle>jackson2</annotationStyle>
                            <generateBuilders>false</generateBuilders>
                            <initializeCollections>true</initializeCollections>
                            <refFragmentPathDelimiters>#/</refFragmentPathDelimiters>
                            <sourceType>json</sourceType>
                            <targetPackage>com.company.app.integration.sabre.stub.rest</targetPackage>
                            <sourceDirectory>${basedir}/src/main/resources/json</sourceDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

Is there any way to have the plugin use the configuration at execution level per goal ?

Plugin version: 0.5.1

Sandheep
  • 517
  • 3
  • 7
  • 18

2 Answers2

2

tl;dr

When running the 'compile' from Maven projects lifecycle, the plugin is considering the configuration from execution and is working as expected.


I am using Intellij and was trying to generate the pojo from Plugins -> jsonschema2pojo -> jsonschema2pojo:generate under 'Maven Projects' window. This was giving the above error and was not taking the configuration per execution.

When I run compile from the Maven Lifecycle, it is picking the configuration in the execution and is generating the files as specified.

I am not yet sure if this is a issue with the plugin or maven or if its a issue at all !!

Sandheep
  • 517
  • 3
  • 7
  • 18
0

Try moving your configuration out to the plugin level and using the parent folder (${baseDir}/src/main/resources) as the sourceDirectory.

Here's an old bug report describing the same thing: https://github.com/joelittlejohn/jsonschema2pojo/issues/145

sebastien
  • 11
  • 3
  • Thanks for the tip. That only takes care of the package creation for the subfolders. I wanted to have two different folders treated as jsonschema and json respectively. – Sandheep Oct 05 '17 at 04:45