I just want to share another GitHub Action (create by me) that you may find useful in your Java projects.
Java projects often use .properties
files to store configuration. Personally, I hate them in favor of YML or even XML (I beg you: use XML to configure Log4j, not .properties
), but still, I have to work with them. There are existing actions in the Marketplace able to parse those, but they usually use grep
and bash
. Although it may work, I think it's more robust to use special facilities, like java.util.Properties
to read values from .properties
files.
So, I wrote a simple Kotlin program that reads Java .properties
and wrapped it into a GitHub Action. This Action makes values from .properties
available in your GitHub Actions workflows.
Returning a single property is as simple as:
- uses: madhead/read-java-properties@latest
id: version
with:
file: gradle.properties
property: version
default: 0.0.1
- run: echo ${{ steps.version.outputs.value }} # Project's version from gradle.properties or 0.0.1 if it is not defined there
Alternatively, you could return all the values from the .properties
file by employing the all
flag:
- uses: madhead/read-java-properties@latest
id: all
with:
file: gradle.properties
all: true
- run: echo ${{ steps.all.outputs.version }} # Project's version from gradle.properties
- run: echo ${{ steps.all.outputs.groupId }} # Project's groupId from gradle.properties
…
That's all for today, just save the link: madhead/read-java-properties, and, as always, feel free to open issues if something is not working as needed or expected.
Top comments (0)