Skip to content

Instantly share code, notes, and snippets.

@dbazile
Created February 6, 2021 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbazile/0d09de25778771487c7a1a2c230ce565 to your computer and use it in GitHub Desktop.
Save dbazile/0d09de25778771487c7a1a2c230ce565 to your computer and use it in GitHub Desktop.
java maven build properties bundler thingymadoodle
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>bazile</groupId>
<artifactId>test-build-props</artifactId>
<version>0.0.0</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
<phase>process-resources</phase>
</execution>
</executions>
<configuration>
<executable>src/main/scripts/props.sh</executable>
<environmentVariables>
<VERSION>${project.version}</VERSION>
</environmentVariables>
<outputFile>target/classes/build.properties</outputFile>
</configuration>
</plugin>
</plugins>
</build>
</project>
#!/bin/bash
set -e
cd "$(dirname $0)"
cat <<-EOT
commit.author=$(git log -1 --format='format:%an <%ae>')
commit.branch=$(git branch --show-current)
commit.sha=$(git log -1 --format='format:%H')
commit.tag=$(git describe --tags 2>/dev/null)
commit.time=$(git log -1 --format='format:%cI')
id=${BUILD_NUMBER:-0}
host=$(hostname --fqdn)
time=$(date --iso-8601=seconds)
user=$USERNAME
version=${VERSION:-$(mvn -B -q help:evaluate -Dexpression=project.version -DforceStdout)}
EOT
$ mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< bazile:test-build-props >-----------------------
[INFO] Building test-build-props 0.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test-build-props ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/david/src/test-git-props/src/main/resources
[INFO]
[INFO] --- exec-maven-plugin:3.0.0:exec (default) @ test-build-props ---
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-build-props ---
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.881 s
[INFO] Finished at: 2021-02-06T17:20:10-05:00
[INFO] ------------------------------------------------------------------------
$ cat -n target/classes/build.properties
1 commit.author=David Bazile <dbazile@users.noreply.github.com>
2 commit.branch=master
3 commit.sha=3c9f6233fd5c92b9bb841b06b0d6db44cded3b59
4 commit.tag=
5 commit.time=2021-02-06T15:43:47-05:00
6 id=0
7 host=kefka.narshe
8 time=2021-02-06T17:20:09-05:00
9 user=david
10 version=0.0.0
@dbazile
Copy link
Author

dbazile commented Feb 6, 2021

...I am aware of this... >_>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment