Skip to content

Commit

Permalink
add task to create .buildinfo file to distSrc
Browse files Browse the repository at this point in the history
* now the source distribution tarball (e.g. apache-freemarker-gae-src-2.3.33.tgz) contains a .buildinfo file containing information about how the source is to be built to get a reproducible build
* based on https://reproducible-builds.org/docs/jvm/
* we can add more information if needed

Example output:

#Effective recorded build environment information
#Tue Dec 26 12:08:57 CET 2023
source.scm.uri=scm\:git\:https\://git-wip-us.apache.org/repos/asf/freemarker.git
build-tool=gradle
build.setup=https\://github.com/apache/freemarker/blob/2.3-gae/README.md\#building-freemarker
java.vendor=Eclipse Adoptium
java.version=17.0.9
os.name=Mac OS X
buildinfo.version=1.0-SNAPSHOT
source.scm.tag=v2.3.33
  • Loading branch information
chrisrueger committed Dec 26, 2023
1 parent 7bedbac commit 3791ef5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.util.stream.Collectors
import java.util.Properties
import java.io.FileOutputStream

plugins {
`freemarker-root`
Expand Down Expand Up @@ -427,6 +429,34 @@ val distBin = tasks.register<Tar>("distBin") {
}
registerDistSupportTasks(distBin)

// Task to generate buildinfo.properties
val createBuildInfo = tasks.register("createBuildInfo") {
doLast {
val buildInfoFile = File(project.buildDir, "tmp/buildinfo/.buildinfo")
buildInfoFile.parentFile.mkdirs()

val props = Properties().apply {
// see https://reproducible-builds.org/docs/jvm/
setProperty("buildinfo.version", "1.0-SNAPSHOT")

setProperty("java.version", System.getProperty("java.version"))
setProperty("java.vendor", System.getProperty("java.vendor"))
setProperty("os.name", System.getProperty("os.name"))

setProperty("source.scm.uri", "scm:git:https://git-wip-us.apache.org/repos/asf/freemarker.git")
setProperty("source.scm.tag", "v${fmExt.versionDef.version}")

setProperty("build-tool", "gradle")
setProperty("build.setup", "https://github.com/apache/freemarker/blob/2.3-gae/README.md#building-freemarker")

}

FileOutputStream(buildInfoFile).use { outputStream ->
props.store(outputStream, "Effective recorded build environment information")
}
}
}

val distSrc = tasks.register<Tar>("distSrc") {
compression = Compression.GZIP
archiveBaseName.set(distArchiveBaseName)
Expand Down Expand Up @@ -458,6 +488,13 @@ val distSrc = tasks.register<Tar>("distSrc") {
"*/*.*~"
)
}


// Depend on the createBuildInfo task and include the generated file
dependsOn(createBuildInfo)
from(File(project.buildDir, "tmp/buildinfo")) {
include(".buildinfo")
}
}
registerDistSupportTasks(distSrc)

Expand Down
1 change: 1 addition & 0 deletions rat-excludes
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ gradle/**

README.md
gradlew.bat
.buildinfo

0 comments on commit 3791ef5

Please sign in to comment.