Skip to content

Commit 4314cb8

Browse files
build: BuildInfo.class
Signed-off-by: Andreas Reichel <[email protected]>
1 parent be92a13 commit 4314cb8

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

build.gradle

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask
22
import com.nwalsh.gradle.saxon.SaxonXsltTask
33

4+
import java.time.Instant
5+
46
buildscript {
57
dependencies {
68
classpath group: 'net.sf.saxon', name: 'Saxon-HE', version: 'latest.release'
@@ -72,6 +74,56 @@ version = getVersion( !System.getenv("RELEASE") )
7274
group = 'com.github.jsqlparser'
7375
description = 'JSQLParser library'
7476

77+
tasks.register('generateBuildInfo') {
78+
outputs.dir layout.buildDirectory.file("resources/main")
79+
doLast {
80+
def outputDir = new File( layout.buildDirectory.file("generated/sources/buildinfo/java/main").get().asFile, "net/sf/jsqlparser")
81+
outputDir.mkdirs()
82+
83+
def gitVersionStr = providers.exec {
84+
commandLine "git", "--no-pager", "-C", project.projectDir, "describe", "--tags", "--always", "--dirty=-SNAPSHOT"
85+
}.standardOutput.asText.get().trim()
86+
87+
def gitCommitStr = providers.exec {
88+
commandLine "git", "--no-pager", "-C", project.projectDir, "rev-parse", "--short", "HEAD"
89+
}.standardOutput.asText.get().trim()
90+
91+
def buildTime = Instant.now().toString()
92+
93+
def content = """\
94+
|package ai.starlake.jsqltranspiler;
95+
|
96+
|public final class BuildInfo {
97+
| public static final String NAME = "${project.name}";
98+
| public static final String VERSION = "${gitVersionStr}";
99+
| public static final String GIT_COMMIT = "${gitCommitStr ?: 'unknown'}";
100+
| public static final String BUILD_TIME = "${buildTime}";
101+
|}
102+
""".stripMargin()
103+
104+
new File(outputDir, "BuildInfo.java").text = content
105+
}
106+
}
107+
108+
// Make sure the file is included in the compiled sources
109+
sourceSets {
110+
main {
111+
java {
112+
srcDir layout.buildDirectory.file("generated/sources/buildinfo/java/main").get().asFile
113+
}
114+
}
115+
}
116+
117+
tasks.withType(Pmd).configureEach {
118+
mustRunAfter("generateBuildInfo")
119+
}
120+
121+
tasks.withType(Checkstyle).configureEach {
122+
exclude '**/module-info.java', '**/package-info.java'
123+
124+
mustRunAfter("generateBuildInfo")
125+
}
126+
75127
repositories {
76128
gradlePluginPortal()
77129
mavenCentral()
@@ -179,6 +231,8 @@ jar {
179231
"Automatic-Module-Name": "net.sf.jsqlparser"
180232
)
181233
}
234+
235+
dependsOn(generateBuildInfo)
182236
}
183237

184238
tasks.register('xmldoc', Javadoc) {

0 commit comments

Comments
 (0)