|
1 | 1 | import se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask |
2 | 2 | import com.nwalsh.gradle.saxon.SaxonXsltTask |
3 | 3 |
|
| 4 | +import java.time.Instant |
| 5 | + |
4 | 6 | buildscript { |
5 | 7 | dependencies { |
6 | 8 | classpath group: 'net.sf.saxon', name: 'Saxon-HE', version: 'latest.release' |
@@ -72,6 +74,56 @@ version = getVersion( !System.getenv("RELEASE") ) |
72 | 74 | group = 'com.github.jsqlparser' |
73 | 75 | description = 'JSQLParser library' |
74 | 76 |
|
| 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 | + |
75 | 127 | repositories { |
76 | 128 | gradlePluginPortal() |
77 | 129 | mavenCentral() |
@@ -179,6 +231,8 @@ jar { |
179 | 231 | "Automatic-Module-Name": "net.sf.jsqlparser" |
180 | 232 | ) |
181 | 233 | } |
| 234 | + |
| 235 | + dependsOn(generateBuildInfo) |
182 | 236 | } |
183 | 237 |
|
184 | 238 | tasks.register('xmldoc', Javadoc) { |
|
0 commit comments