Last active
January 23, 2019 11:23
-
-
Save ebuildy/0e1b79cb9db11edd0a7af4b875038efc to your computer and use it in GitHub Desktop.
Gradle task to create release note
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
... | |
id "org.ajoberstar.grgit" version "3.0.0" | |
} | |
task createReleaseReportFile() { | |
doLast { | |
file("$projectDir/src/main/resources/release_note.properties").text = """## Automated generated by Gradle ## | |
version=${file("VERSION").text.trim()} | |
revision=${Grgit.open(dir: '.').head().id} | |
time=${new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date())} | |
author=${System.properties['user.name']} | |
""" | |
} | |
} | |
compileJava { | |
dependsOn createReleaseReportFile | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FileNotFoundException; | |
import java.io.InputStream; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Properties; | |
class Read { | |
final private Map<String, String> releaseNote = new HashMap<>(); | |
private void loadReleaseNote() { | |
final Properties buffer = new Properties(); | |
final ClassLoader classLoader = getClass().getClassLoader(); | |
final String releaseNoteFilePath = "release_note.properties"; | |
try { | |
final InputStream inputStream = classLoader.getResourceAsStream(releaseNoteFilePath); | |
if (inputStream != null) { | |
buffer.load(inputStream); | |
} else { | |
throw new FileNotFoundException("property file '" + releaseNoteFilePath + "' not found in the classpath"); | |
} | |
} catch (Exception e) { | |
logger.error("loading release_note", e); | |
} | |
for (Map.Entry<Object, Object> entry : buffer.entrySet()) { | |
releaseNote.put(entry.getKey().toString(), entry.getValue().toString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment