jsonschema-maven-plugin: add `deleteExistingSchemas`
Please add an an option for jsonschema-maven-plugin:
deleteExistingSchemas: true|false:
If true, existing schemas within the defined SchemaFilePath are deleted before new ones are generated.
Example:
<plugin>
<groupId>com.github.victools</groupId>
<artifactId>jsonschema-maven-plugin</artifactId>
<version>${jsonschema.version}</version>
<executions>
<execution>
<?m2e ignore?>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaFilePath>src/main/resources/schemas</schemaFilePath>
<!-- missing configuration property -->
<deleteExistingFiles>true</deleteExistingFiles>
..
</plugin>
Currently it seems that only existing files are overwritten and already generated schemas remain untouched (even if classNames or packageNames have been changed).
Hi @nimo23,
Is the Maven clean command not cleaning it up for you? That would be the standard approach in my view.
If the Maven plugin didn't discard the whole directory, it would be hard-pressed to pick the exact files to delete.
If it can be avoided, I'd rather not add this to the plugin directly.
However, if there is no other way, I'm open to pull requests to include the extra parameter.
Is the Maven clean command not cleaning it up for you? That would be the standard approach in my view.
Having someting like
<schemaFilePath>src/main/resources/schemas</schemaFilePath>
will not be cleaned by maven clean because it's a directory within src/main/resources/. The clean will only clean files from the target-directory.
it would be hard-pressed to pick the exact files to delete.
No need to pick the exact files to delete. It is enough just to delete all the content (with subfolders) in the specified folder (in this example: src/main/resources/schemas).
Hi @nimo23,
How about assigning a dedicated directory for the generated schema files, that can then be targeted by the clean command?
Or use something like the following to get rid of this particular directory's contents too?
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.6.1</version>
<configuration>
<filesets>
<fileset>
<directory>src/main/resources/schemas</directory>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
How about assigning a dedicated directory for the generated schema files, that can then be targeted by the clean command?
Sure. This works. However, this needs to be set up by the user. Normally, the user expects that previously generated files from jsonschema-maven-plugin that are not listed in its configuration-tag will be automatically deleted.
It could at least be documented that previously generated files are not automatically deleted and the user must use the maven-clean plugin if he wants to delete such obsolete files.
I don't quite agree with that expectation.
If you want them to be removed each time, then the target folder is the right place for the schema files.
Putting them in the main folder indicates, that they are supposed to remain there.
Alternatively, a dedicated generated folder for such files, that would also be cleaned-up automatically.
It boils down to the folder selection, whether the old schema files get discarded or not.
If you want them to be removed each time, then the target folder is the right place for the schema files.
Yes, but imagine that the consuming client side framework has a folder within src/main/webapp/jsonschema, then the user must delete those files while developing because jsonschema-maven-plugin does not care of stale schema generated files.
Yes, I understand that occasionally the need for clearing the target arises. E.g., when you cannot just put the generated files in the mirrored target/main/webapp/jsonschema folder.
My opinion still holds though. Even the compiler plugin does not delete old compiled files itself. That's what the clean command is responsible for. It is consistent to do the same here.
If there are additional folders to be cleaned up, that's to be configured on the plugin that performs such clean-ups.
Even the compiler plugin does not delete old compiled files itself. That's what the clean command is responsible for.
Would it be possible for the plugin to call this cleanup step if deleteExistingSchemas=true? If not, then at least it could be documented that the plugin does not remove obsolete files itself.