Improve build scripts
All checks were successful
PRs & Pushes / build (push) Successful in 1m46s
PRs & Pushes / test (push) Successful in 1m44s
PRs & Pushes / build-apidoc (push) Successful in 1m44s

Thanks solonovamax! She/he/they helped improve the engine's build scripts and gave a lot of tips when working with Gradle.

Website: https://solonovamax.gay
Fedi: https://tech.lgbt/@solonovamax
GitHub: https://github.com/solonovamax
This commit is contained in:
JeremyStar™ 2024-12-24 23:56:42 +01:00
parent b133f7e3a7
commit e2e5040055
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
3 changed files with 56 additions and 46 deletions

View file

@ -44,16 +44,6 @@ import java.nio.file.LinkOption
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
// Buildscript
buildscript {
// Repositories
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
}
}
// Plugins // Plugins
plugins { plugins {
id("java-library") id("java-library")
@ -113,8 +103,8 @@ allprojects {
// Java // Java
java { java {
// Java version // Java version
sourceCompatibility = JavaVersion.valueOf("VERSION_${property("languageJava") as String}") sourceCompatibility = JavaVersion.toVersion(property("languageJava") as String)
targetCompatibility = JavaVersion.valueOf("VERSION_${property("languageJava") as String}") targetCompatibility = JavaVersion.toVersion(property("languageJava") as String)
if (!(hasProperty("java.skipToolchainSpecification") && property("java.skipToolchainSpecification") as String == "true")) if (!(hasProperty("java.skipToolchainSpecification") && property("java.skipToolchainSpecification") as String == "true"))
toolchain { toolchain {
@ -130,7 +120,7 @@ allprojects {
verbose = true verbose = true
// Set target metadata // Set target metadata
jvmTarget = JvmTarget.valueOf("JVM_${property("languageJava") as String}") jvmTarget = JvmTarget.fromTarget(property("languageJava") as String)
} }
// Unit testing // Unit testing
@ -218,17 +208,17 @@ allprojects {
// -> Copy task // -> Copy task
tasks.register("copyGitProperties") { tasks.register("copyGitProperties") {
dependsOn(tasks.generateGitProperties) dependsOn(tasks.generateGitProperties)
inputs.file("${project.projectDir}/build/resources/main/git.properties")
doLast { doLast {
if (rootProject == project) if (rootProject == project)
return@doLast return@doLast
val target: File = file("${project.projectDir}/src/main/resources/sosengine-${project.name.replace(":", "-")}-git.properties") file(inputs.files.first())
val source: File = file("${project.projectDir}/build/resources/main/git.properties") .copyTo(
file("${project.projectDir}/src/main/resources/sosengine-${project.name.replace(":", "-")}-git.properties"),
if (Files.exists(target.toPath(), LinkOption.NOFOLLOW_LINKS)) overwrite = true
Files.delete(target.toPath()) )
Files.move(source.toPath(), target.toPath())
} }
} }
tasks.processResources { tasks.processResources {
@ -238,16 +228,17 @@ allprojects {
// Gradle properties // Gradle properties
// -> Copy task // -> Copy task
tasks.register("copyGradleProperties") { tasks.register("copyGradleProperties") {
inputs.file("${project(":").projectDir.path}/gradle.properties")
doLast { doLast {
if (rootProject == project) if (rootProject == project)
return@doLast return@doLast
val target: File = file("${project.projectDir}/src/main/resources/sosengine-${project.name.replace(":", "-")}-gradle.properties") file(inputs.files.first())
val source: File = file("${project(":").projectDir.path}/gradle.properties") .copyTo(
file("${project.projectDir}/src/main/resources/sosengine-${project.name.replace(":", "-")}-gradle.properties"),
if (Files.exists(target.toPath(), LinkOption.NOFOLLOW_LINKS)) overwrite = true
Files.delete(target.toPath()) )
Files.copy(source.toPath(), target.toPath())
} }
} }
tasks.processResources { tasks.processResources {

View file

@ -17,13 +17,19 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
// Plugin management
pluginManagement {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
}
}
// Project settings // Project settings
rootProject.name = "sos!engine" rootProject.name = "sos!engine"
// Subprojects // Subprojects
// -> Root
include("")
// -> Base // -> Base
include("base") include("base")

View file

@ -32,7 +32,7 @@ dependencies {
// Configure JAR // Configure JAR
tasks.withType<Jar> { tasks.withType<Jar> {
manifest { manifest {
attributes.put("Main-Class", "de.staropensource.engine.testapp.Main") attributes["Main-Class"] = "de.staropensource.engine.testapp.Main"
} }
} }
@ -41,24 +41,37 @@ application {
mainClass = "de.staropensource.engine.testapp.Main" mainClass = "de.staropensource.engine.testapp.Main"
// JVM arguments // JVM arguments
val jvmArgs: MutableList<String> = mutableListOf() applicationDefaultJvmArgs = buildList {
// -> JVM // Unlock more VM options
jvmArgs.add("-XX:+UnlockDiagnosticVMOptions") add("-XX:+UnlockDiagnosticVMOptions")
add("-XX:+UnlockExperimentalVMOptions")
if (hasProperty("jvm.logGC") && property("jvm.logGC") as String == "true") // VM settings
jvmArgs.add("-Xlog:gc") // -> Log garbage collection
if (hasProperty("jvm.logJITandAOT") && property("jvm.logJITandAOT") as String == "true") { if (
jvmArgs.add("-XX:+PrintCompilation") hasProperty("jvm.logGC")
jvmArgs.add("-XX:+PrintInlining") && property("jvm.logGC") as String == "true"
)
add("-Xlog:gc")
// -> Log JIT & AOT
if (
hasProperty("jvm.logJITandAOT")
&& property("jvm.logJITandAOT") as String == "true"
) {
add("-XX:+PrintCompilation")
add("-XX:+PrintInlining")
} }
// -> Select garbage collector
if (hasProperty("jvm.garbageCollector")) if (hasProperty("jvm.garbageCollector"))
when (property("jvm.garbageCollector")) { when (property("jvm.garbageCollector")) {
"epsilon" -> jvmArgs.add("-XX:+UseEpsilonGC") "epsilon" -> add("-XX:+UseEpsilonGC")
"serial" -> jvmArgs.add("-XX:+UseSerialGC") "serial" -> add("-XX:+UseSerialGC")
"g1" -> jvmArgs.add("-XX:+UseG1GC") "g1" -> add("-XX:+UseG1GC")
} }
// -> Jansi
jvmArgs.add("-Djansi.mode=force")
applicationDefaultJvmArgs = jvmArgs // Jansi
add("-Djansi.mode=force")
}
} }