joelittlejohn / jsonschema2pojo

Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
http://www.jsonschema2pojo.org
Apache License 2.0
6.24k stars 1.66k forks source link

Allow URL(s) as source in jsonschema2pojo-gradle-plugin #1554

Closed unkish closed 2 months ago

unkish commented 1 year ago

Closes #1010

Seems it got broken with #748, specifically this line.

Note: users would have to explicitly invoke clean whenever they have URL as source and know that content behind URL has changed

unkish commented 1 year ago

Looks like JsonSchemaPluginSpec::java is executed prior snapshot artifact is generated causing build failure. Reverting changes from build.gradle would help but there would be no "test" to validate the fix later on.

@joelittlejohn any thoughts on how to proceed ?

One way to validate my claim would be to rename JsonSchemaPluginSpec to JsonSchemaPluginSpecIT and add following section to jsonschema2pojo-gradle-plugin\pom.xml:

            <plugin>
                <!-- switch off surefire, there's no unit tests in this module -->
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>install</phase>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
joelittlejohn commented 1 year ago

Ah yes, thanks @unkish. I had noticed this a while back, when there was some problem in the plugin but it did not get shown until after an install.

I think your solution to use failsafe instead of surefire and attach it to a later phase is a good one :+1:

Is this ready to merge now?

unkish commented 1 year ago

In last change that succeeded I've split test into unit (jsonschema2pojo-gradle-plugin/src/test/groovy/org/jsonschema2pojo/gradle/JsonSchemaPluginSpec.groovy) and integration test (jsonschema2pojo-gradle-plugin/src/integrationTest/groovy/org/jsonschema2pojo/gradle/GradleBuildIT.groovy) and configured jsonschema2pojo-gradle-plugin to execute both: failsafe and surefie.

I can switch it to run only failsafe and disable surefire - would that be preferred way ?

unkish commented 1 year ago

@joelittlejohn adjusted jsonschema2pojo-gradle-plugin such that it would only execute maven-failsafe-plugin in install phase and skip running maven-surefire-plugin. With these changes it should be ready (if there is nothing that I've missed)

joelittlejohn commented 1 year ago

Sorry @unkish I misunderstood. I didn't realise there were unit tests. I'm happy to use surefire and failsafe, each for the appropriate kind of test.

unkish commented 1 year ago

@joelittlejohn no worries.

I have one concern though: it seems that at present github actions will skip integration tests in jsonschema2pojo-gradle-plugin as:

      - name: Verify with Maven
        run: mvn verify -B

will not trigger it since verify is prior install phase, and

      - name: Install latest jsonschema2pojo SNAPSHOT
        run: mvn -U -B install -DskipTests -Dmaven.javadoc.skip -Dmaven.site.skip

will not trigger it due -DskipTests.
I would imagine that something like:

      - name: Verify with Maven
        run: mvn verify -B
      - name: Verify jsonschema2pojo-gradle-plugin integration tests
        run: mvn -U -B install -DskipTests -Dmaven.javadoc.skip -Dmaven.site.skip -pl jsonschema2pojo-gradle-plugin -am
        run: mvn -U -B install -pl jsonschema2pojo-gradle-plugin

would "remedy" the issue, however I'm not sure whether it is an overall good solution or not