A Maven plugin that wraps the JsonPath Java library, enabling JSON parsing and querying directly within Maven builds.
- Parse JSON files or inline JSON strings.
- Extract values from JSON using JsonPath expressions.
- Automatically update
.envfiles with extracted values. - Automatically update
.gitignore
- Java 21 or higher
- Maven 3.9.9 or higher
To use the plugin, add the following to your pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.metalib.maven.plugin</groupId>
<artifactId>json-path-maven-plugin</artifactId>
<version>0.0.3</version>
</plugin>
</plugins>
</build>The plugin accepts an array of JsonInput objects via the paths parameter. Each JsonInput object can specify:
format: The format of the input (e.g., JSON).text: Inline JSON content.file: A file containing JSON content.queryMaps: A set of key-value pairs where the key is the property name and the value is the JsonPath query.
text and file parameters are mutually exclusive.
Here is an example configuration in your pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.metalib.maven.plugin</groupId>
<artifactId>json-path-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<paths>
<path>
<file>json-text.json</file>
<queryMaps>
<FOO>$.foo</FOO>
<BAR_BAZ>$.bar.baz</BAR_BAZ>
</queryMaps>
</path>
</paths>
</configuration>
</plugin>
</plugins>
</build>with the sample input file json-text.json:
{
"foo": "bar",
"bar": {
"baz": "qux"
}
}This goal processes the JSON inputs and performs the following:
- Extracts values from JSON using the specified JsonPath queries.
- Updates the
.envfile in the project directory with the extracted values. - Ensures the
.envfile is listed in.gitignoreto prevent accidental commits.
To execute the plugin, run:
mvn jq:pathsIt will create or update .env as shown:
#Wed Apr 23 16:58:10 CDT 2025
BAR_BAZ=qux
FOO=barIt will make sure that there is a
### protecting .env file ###
.envThis project is licensed under the Apache License, version 2.0. See the LICENSE file for details.