Utilize the gradle kotlin DSL for cleaner build scripts

This commit is contained in:
Johannes Frohnmeyer 2022-07-23 20:34:23 +02:00
parent 663e143c4b
commit c1f3f7e57a
Signed by: Johannes
GPG Key ID: E76429612C2929F4
8 changed files with 232 additions and 235 deletions

View File

@ -1,133 +0,0 @@
import org.gradle.internal.os.OperatingSystem
plugins {
id 'java'
id 'application'
id 'com.github.johnrengelman.shadow' version '7.0.0'
id "maven-publish"
id "org.ajoberstar.grgit" version "3.1.0"
}
application {
mainClass = 'io.gitlab.jfronny.inceptum.Inceptum'
}
repositories {
mavenCentral()
maven {
url 'https://gitlab.com/api/v4/projects/35745143/packages/maven'
}
}
ext.currentVer = "0.0.0+nogit"
if (grgit != null) {
ext.currentVer = "0.0.0+notag"
grgit.open(dir: rootProject.projectDir.toString())
def tagList = grgit.tag.list()
tagList.sort((left, right) -> right.commit.dateTime.compareTo(left.commit.dateTime))
if (tagList.size() >= 1) {
ext.currentVer = tagList.get(0).getName()
}
}
println("Building Inceptum " + ext.currentVer)
allprojects {
version "$rootProject.ext.currentVer" + (project.hasProperty('release') ? "" : "-" + (project.hasProperty('timestamp') ? project.getProperty('timestamp') : Instant.now().getEpochSecond()))
group 'io.gitlab.jfronny.inceptum'
}
ext {
lwjglVersion = '3.3.1'
imguiVersion = '1.86.4'
logbackVersion = '1.3.0-alpha15'
jfCommonsVersion = '2022.7.4+11-13-3'
jgitVersion = '6.1.0.202203080745-r'
flavorProp = project.hasProperty('flavor') ? project.getProperty('flavor') : 'custom'
flavor = flavorProp
isPublic = project.hasProperty('public')
isRelease = project.hasProperty('release')
}
if (flavor == 'custom') {
switch (OperatingSystem.current()) {
case OperatingSystem.WINDOWS:
project.ext.flavor = 'windows'
break
case OperatingSystem.LINUX:
project.ext.flavor = 'linux'
break
case OperatingSystem.MAC_OS:
project.ext.flavor = 'macos'
break
}
}
dependencies {
implementation "ch.qos.logback:logback-classic:$logbackVersion"
implementation "io.gitlab.jfronny:commons:$jfCommonsVersion"
implementation "io.gitlab.jfronny:commons-gson:$jfCommonsVersion"
implementation "io.gitlab.jfronny:commons-slf4j:$jfCommonsVersion"
implementation "org.eclipse.jgit:org.eclipse.jgit:$jgitVersion"
implementation project(":wrapper")
implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
['', '-opengl', '-glfw', '-tinyfd'].each {
implementation "org.lwjgl:lwjgl$it:$lwjglVersion"
if (flavor == 'windows' || flavor == 'fat') implementation "org.lwjgl:lwjgl$it::natives-windows"
if (flavor == 'linux' || flavor == 'fat') implementation "org.lwjgl:lwjgl$it::natives-linux"
if (flavor == 'macos' || flavor == 'fat') implementation "org.lwjgl:lwjgl$it::natives-macos"
}
implementation "io.github.spair:imgui-java-binding:$imguiVersion" // https://github.com/SpaiR/imgui-java
implementation "io.github.spair:imgui-java-lwjgl3:$imguiVersion"
if (flavor == 'windows' || flavor == 'fat') implementation "io.github.spair:imgui-java-natives-windows:$imguiVersion"
if (flavor == 'linux' || flavor == 'fat') implementation "io.github.spair:imgui-java-natives-linux:$imguiVersion"
if (flavor == 'macos' || flavor == 'fat') implementation "io.github.spair:imgui-java-natives-macos:$imguiVersion"
}
processResources {
inputs.property "version", project.version
filesMatching("version.json") {
expand "version": project.version
filter { line -> line.replace("@flavor@", project.ext.flavorProp) }
filter { line -> line.replace("@public@", "$project.ext.isPublic") }
filter { line -> line.replace("@release@", "$project.ext.isRelease") }
filter { line -> line.replace("@jvm@", "$project.sourceCompatibility") }
}
}
shadowJar {
archiveClassifier.set(flavorProp)
exclude "about.html"
exclude "plugin.properties"
exclude "META-INF/**"
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact(shadowJar) {
builtBy shadowJar
}
}
}
if (project.ext.isPublic) {
repositories.maven {
url = "https://gitlab.com/api/v4/projects/30862253/packages/maven"
name = "gitlab"
credentials(HttpHeaderCredentials) {
name = "Job-Token"
value = System.getenv().CI_JOB_TOKEN
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
repositories.mavenLocal()
}

122
build.gradle.kts Normal file
View File

@ -0,0 +1,122 @@
import org.gradle.internal.os.OperatingSystem
import org.ajoberstar.grgit.Grgit
plugins {
java
application
`maven-publish`
id("com.github.johnrengelman.shadow") version "7.1.2"
id("org.ajoberstar.grgit") version "5.0.0" apply false
}
application {
mainClass.set("io.gitlab.jfronny.inceptum.Inceptum")
}
repositories {
mavenCentral()
maven {
setUrl("https://gitlab.com/api/v4/projects/35745143/packages/maven")
}
}
var currentVer = "0.0.0+nogit"
if (File(".git").exists()) {
val grgit: Grgit = Grgit.open(mapOf("dir" to rootProject.projectDir.toString()))
currentVer = "0.0.0+notag"
val tagList = grgit.tag.list()
tagList.sortWith { left, right -> right.commit.dateTime.compareTo(left.commit.dateTime) }
if (tagList.isNotEmpty()) {
currentVer = tagList[0].name
}
}
println("Building Inceptum $currentVer")
allprojects {
version = currentVer + if (project.hasProperty("release")) "" else "-" + (if (project.hasProperty("timestamp")) project.property("timestamp") else "${System.currentTimeMillis() / 1000L}")
group = "io.gitlab.jfronny.inceptum"
}
val lwjglVersion by extra("3.3.1")
val imguiVersion by extra("1.86.4")
val logbackVersion by extra("1.3.0-alpha15")
val jfCommonsVersion by extra("2022.7.4+11-13-3")
val jgitVersion by extra("6.2.0.202206071550-r")
val flavorProp: String by extra(if (project.hasProperty("flavor")) "${project.property("flavor")}" else "custom")
val flavor: String by extra(if (flavorProp != "custom") flavorProp else when (OperatingSystem.current()) {
OperatingSystem.WINDOWS -> "windows"
OperatingSystem.LINUX -> "linux"
OperatingSystem.MAC_OS -> "macos"
else -> throw IllegalStateException()
})
val isPublic by extra(project.hasProperty("public"))
val isRelease by extra(project.hasProperty("release"))
dependencies {
implementation("ch.qos.logback:logback-classic:$logbackVersion")
implementation("io.gitlab.jfronny:commons:$jfCommonsVersion")
implementation("io.gitlab.jfronny:commons-gson:$jfCommonsVersion")
implementation("io.gitlab.jfronny:commons-slf4j:$jfCommonsVersion")
implementation("org.eclipse.jgit:org.eclipse.jgit:$jgitVersion")
implementation(project(":wrapper"))
implementation(platform("org.lwjgl:lwjgl-bom:$lwjglVersion"))
arrayOf("", "-opengl", "-glfw", "-tinyfd").forEach { it ->
implementation("org.lwjgl:lwjgl$it:$lwjglVersion")
if (flavor == "windows" || flavor == "fat") implementation("org.lwjgl:lwjgl$it::natives-windows")
if (flavor == "linux" || flavor == "fat") implementation("org.lwjgl:lwjgl$it::natives-linux")
if (flavor == "macos" || flavor == "fat") implementation("org.lwjgl:lwjgl$it::natives-macos")
}
implementation("io.github.spair:imgui-java-binding:$imguiVersion") // https://github.com/SpaiR/imgui-java
implementation ("io.github.spair:imgui-java-lwjgl3:$imguiVersion")
if (flavor == "windows" || flavor == "fat") implementation("io.github.spair:imgui-java-natives-windows:$imguiVersion")
if (flavor == "linux" || flavor == "fat") implementation("io.github.spair:imgui-java-natives-linux:$imguiVersion")
if (flavor == "macos" || flavor == "fat") implementation("io.github.spair:imgui-java-natives-macos:$imguiVersion")
}
tasks.processResources {
inputs.property("version", project.version)
filesMatching("version.json") {
expand(
"version" to project.version,
"flavor" to flavorProp,
"isPublic" to isPublic,
"isRelease" to isRelease,
"jvm" to project.java.targetCompatibility
)
}
}
tasks.shadowJar {
archiveClassifier.set(flavorProp)
exclude("about.html")
exclude("plugin.properties")
exclude("META-INF/**")
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
artifact(tasks.shadowJar) {
builtBy(tasks.shadowJar)
}
}
}
if (isPublic) {
repositories.maven {
url = uri("https://gitlab.com/api/v4/projects/30862253/packages/maven")
name = "gitlab"
credentials(HttpHeaderCredentials::class) {
name = "Job-Token"
value = System.getenv().get("CI_JOB_TOKEN")
}
}
}
repositories.mavenLocal()
}

View File

@ -1,3 +0,0 @@
rootProject.name = 'Inceptum'
include 'wrapper'

3
settings.gradle.kts Normal file
View File

@ -0,0 +1,3 @@
rootProject.name = "Inceptum"
include("wrapper")

View File

@ -1,7 +1,7 @@
{
"version": "${version}",
"flavor": "@flavor@",
"isPublic": @public@,
"isRelease": @release@,
"jvm": @jvm@
"flavor": "${flavor}",
"isPublic": ${isPublic},
"isRelease": ${isRelease},
"jvm": ${jvm}
}

View File

@ -1,91 +0,0 @@
plugins {
id 'java'
id 'application'
id "de.undercouch.download" version "4.1.1"
id 'com.github.johnrengelman.shadow'
id "maven-publish"
}
application {
mainClass = 'io.gitlab.jfronny.inceptum.WrapperStrap'
}
repositories {
mavenCentral()
maven {
url 'https://gitlab.com/api/v4/projects/35745143/packages/maven'
}
}
dependencies {
implementation "ch.qos.logback:logback-classic:${rootProject.logbackVersion}"
implementation "io.gitlab.jfronny:commons:${rootProject.jfCommonsVersion}"
implementation "io.gitlab.jfronny:commons-gson:${rootProject.jfCommonsVersion}"
implementation "io.gitlab.jfronny:commons-slf4j:${rootProject.jfCommonsVersion}"
}
processResources {
inputs.property "version", project.version
filesMatching("version.json") {
expand "version": project.version
filter { line -> line.replace("@flavor@", rootProject.ext.flavorProp) }
filter { line -> line.replace("@public@", "$rootProject.ext.isPublic") }
filter { line -> line.replace("@jvm@", "$rootProject.sourceCompatibility") }
}
}
class FileOutput extends DefaultTask {
@OutputFile
File output
}
def bootstrapVersion = "0.2.1"
def bootstrapArch = "i686"
task downloadBootstrap(type: Download) {
src "https://maven.fabricmc.net/net/fabricmc/fabric-installer-native-bootstrap/windows-${bootstrapArch}/${bootstrapVersion}/windows-${bootstrapArch}-${bootstrapVersion}.exe"
dest project.buildDir
}
task nativeExe(dependsOn: [downloadBootstrap, shadowJar], type: FileOutput) {
output = file("${projectDir}/build/libs/${archivesBaseName}-${project.version}.exe")
outputs.upToDateWhen { false }
doFirst {
output.delete()
}
doLast {
output.createNewFile()
output.setBytes downloadBootstrap.outputFiles.first().readBytes()
output.append shadowJar.archiveFile.get().getAsFile().readBytes()
}
}
if (flavor == 'windows') build.dependsOn nativeExe
publishing {
publications {
mavenJava(MavenPublication) {
artifact(shadowJar) {
builtBy shadowJar
}
}
}
if (rootProject.ext.isPublic) {
repositories.maven {
url = "https://gitlab.com/api/v4/projects/30862253/packages/maven"
name = "gitlab"
credentials(HttpHeaderCredentials) {
name = "Job-Token"
value = System.getenv().CI_JOB_TOKEN
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
repositories.mavenLocal()
}

99
wrapper/build.gradle.kts Normal file
View File

@ -0,0 +1,99 @@
import java.io.FileOutputStream
import de.undercouch.gradle.tasks.download.Download
plugins {
java
application
`maven-publish`
id("com.github.johnrengelman.shadow") version "7.1.2"
id("de.undercouch.download") version "5.1.0"
}
application {
mainClass.set("io.gitlab.jfronny.inceptum.WrapperStrap")
}
repositories {
mavenCentral()
maven {
setUrl("https://gitlab.com/api/v4/projects/35745143/packages/maven")
}
}
dependencies {
implementation("ch.qos.logback:logback-classic:${rootProject.extra["logbackVersion"]}")
implementation("io.gitlab.jfronny:commons:${rootProject.extra["jfCommonsVersion"]}")
implementation("io.gitlab.jfronny:commons-gson:${rootProject.extra["jfCommonsVersion"]}")
implementation("io.gitlab.jfronny:commons-slf4j:${rootProject.extra["jfCommonsVersion"]}")
}
tasks.processResources {
inputs.property("version", project.version)
filesMatching("version.json") {
expand(
"version" to project.version,
"flavor" to rootProject.extra["flavorProp"],
"isPublic" to rootProject.extra["isPublic"],
"isRelease" to rootProject.extra["isRelease"],
"jvm" to project.java.targetCompatibility
)
}
}
abstract class FileOutput : DefaultTask() {
@get:OutputFile
abstract var output: File
}
val bootstrapVersion = "0.2.1"
val bootstrapArch = "i686"
val downloadBootstrap by tasks.registering(Download::class) {
src("https://maven.fabricmc.net/net/fabricmc/fabric-installer-native-bootstrap/windows-${bootstrapArch}/${bootstrapVersion}/windows-${bootstrapArch}-${bootstrapVersion}.exe")
dest(project.buildDir)
}
val nativeExe by tasks.registering(FileOutput::class) {
dependsOn(downloadBootstrap)
dependsOn(tasks.shadowJar)
output = file("${buildDir}-${project.version}.exe")
outputs.upToDateWhen { false }
doFirst {
output.delete()
}
doLast {
output.createNewFile()
FileOutputStream(output).use { w ->
w.write(downloadBootstrap.get().outputFiles.first().readBytes())
w.write(tasks.shadowJar.get().archiveFile.get().asFile.readBytes())
}
}
}
if (rootProject.extra["flavor"] == "windows") tasks.build.get().dependsOn(nativeExe)
publishing {
publications {
create<MavenPublication>("mavenJava") {
artifact(tasks.shadowJar) {
builtBy(tasks.shadowJar)
}
}
}
if (rootProject.extra["isPublic"] == true) {
repositories.maven {
url = uri("https://gitlab.com/api/v4/projects/30862253/packages/maven")
name = "gitlab"
credentials(HttpHeaderCredentials::class) {
name = "Job-Token"
value = System.getenv().get("CI_JOB_TOKEN")
}
}
}
repositories.mavenLocal()
}

View File

@ -1,7 +1,7 @@
{
"version": "${version}",
"flavor": "@flavor@",
"isPublic": @public@,
"isRelease": @release@,
"jvm": @jvm@
"flavor": "${flavor}",
"isPublic": ${isPublic},
"isRelease": ${isRelease},
"jvm": ${jvm}
}