Skip to content

Commit

Permalink
chore(docs): describe loading Maven plugin module from test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
CarstenWickner committed Oct 25, 2023
1 parent 9eaf911 commit 5428a56
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion slate-docs/source/includes/_maven-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ The considered `<classpath>` may be further specified as one of four values:
- `WITH_COMPILE_DEPENDENCIES` : `PROJECT_ONLY` and compile dependencies
- `WITH_RUNTIME_DEPENDENCIES` : `PROJECT_ONLY` and runtime dependencies (default, if unspecified)
- `WITH_ALL_DEPENDENCIES` : all of the above

- `WITH_ALL_DEPENDENCIES_AND_TESTS` : all of the above, with the addition of the current project's test files
Note that this requires a different `<phase>` (e.g., `test-compile`) being specified on the `<execution>`.
----

By default, the plugin aborts if the glob pattern does not match any class. If this is not desired, the `<failIfNoClassesMatch>` property can be set to `false`.
Expand Down Expand Up @@ -144,3 +145,23 @@ One possibility within such a custom Module (as mentioned above) is to configure
The file contents are being produced by the schema generator's associated `ObjectMapper`.
That default `ObjectMapper` can be replaced, e.g., to opt-out of the default pretty-printing or changing the file format to YAML.
The given example requires the inclusion of the extra `com.fasterxml.jackson.dataformat:jackson-dataformat-yaml` dependency.

### Loading custom Module from test classes

```xml
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
```

When using a custom Module (as mentioned above) for additional configuration options, but don't want to include it among your application code,
you can either package it as separate artifact and include that as dependency of the plugin (not going into further detail here)
or the custom Module class can be included in your test packages.
When you do the latter, the Maven plugin will by default not be able to load that class, since it won't be compiled yet in the Maven phase the schema generation is being executed at by default.
The Maven `compile` phase is when the schema generation gets triggered by default.
If you want the test classes (including the custom Module) to be available, a later phase (most likely: `test-compile`) needs to be specified.

0 comments on commit 5428a56

Please sign in to comment.