Engine/build.gradle.kts

248 lines
8.5 KiB
Text
Raw Normal View History

/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU General Public License v3.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2024-12-12 23:10:29 +01:00
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.gradle.DokkaTask
2024-12-13 02:59:25 +01:00
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2024-12-12 23:10:29 +01:00
import java.net.URI
2024-12-18 17:41:53 +01:00
import java.nio.file.Files
import java.nio.file.LinkOption
2024-12-12 23:10:29 +01:00
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
* with an exception allowing classpath linking.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// Plugins
plugins {
id("java-library")
id("maven-publish")
// Kotlin support
id("org.jetbrains.kotlin.jvm") version("2.0.0")
// Dokka
id("org.jetbrains.dokka") version("1.9.20")
// Git properties
id("com.gorylenko.gradle-git-properties") version("2.4.2")
}
allprojects {
// Plugins
apply(plugin = "java")
apply(plugin = "java-library")
apply(plugin = "maven-publish")
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "com.gorylenko.gradle-git-properties")
// Version
2024-12-13 02:59:35 +01:00
version = "${property("versionRelease") as String}-${property("versionType") as String}${property("versionTyperelease") as String}"
2024-12-12 23:10:29 +01:00
if (property("versionFork") != "")
2024-12-13 02:59:35 +01:00
version = "${version as String}-${property("versionFork") as String}"
2024-12-12 23:10:29 +01:00
if (property("versionCompanion") != "")
2024-12-13 02:59:35 +01:00
version = "${version as String}+${property("versionCompanion") as String}"
2024-12-12 23:10:29 +01:00
// Repositories
repositories {
mavenLocal()
mavenCentral()
}
// Dependencies
dependencies {
// Kotlin support
2024-12-19 02:49:32 +01:00
kotlin(property("dependencyKotlin_StdIdentifier") as String)
kotlin(property("dependencyKotlin_StdLibIdentifier") as String)
implementation("${property("dependencyKotlin_ReflectIdentifier") as String}:${property("dependencyKotlinVersion") as String}")
implementation("${property("dependencyKotlin_DateTimeIdentifier") as String}:${property("dependencyKotlin_DateTimeVersion") as String}")
2024-12-15 01:12:07 +01:00
2024-12-15 22:33:31 +01:00
// Unit testing
// -> Kotlin
testImplementation(kotlin("test"))
// -> JUnit
2024-12-19 02:49:32 +01:00
testImplementation(platform("${property("testDependencyJUnit_BOMIdentifier")}:${property("testDependencyJUnitVersion")}"))
testImplementation("${property("testDependencyJUnit_JupiterIdentifier")}")
testRuntimeOnly("${property("testDependencyJUnit_PlatformIdentifier")}")
2024-12-15 22:33:31 +01:00
// -> sos!engine
testImplementation(project(":testing"))
2024-12-12 23:10:29 +01:00
}
// Java
java {
// Java version
sourceCompatibility = JavaVersion.toVersion(property("languageJava") as String)
targetCompatibility = JavaVersion.toVersion(property("languageJava") as String)
2024-12-12 23:10:29 +01:00
if (!(hasProperty("java.skipToolchainSpecification") && property("java.skipToolchainSpecification") as String == "true"))
toolchain {
2024-12-19 02:49:32 +01:00
languageVersion = JavaLanguageVersion.of(property("languageJava") as String)
}
2024-12-12 23:10:29 +01:00
}
2024-12-13 02:59:25 +01:00
// Kotlin
kotlin.compilerOptions {
// Configuration
progressiveMode = true
allWarningsAsErrors = true
verbose = true
// Set target metadata
jvmTarget = JvmTarget.fromTarget(property("languageJava") as String)
2024-12-13 02:59:25 +01:00
}
2024-12-18 17:41:53 +01:00
// Unit testing
// -> Configure Gradle to use JUnit
tasks.test {
useJUnitPlatform()
testLogging {
events(
"passed",
"skipped",
"failed"
)
}
maxParallelForks = 1
}
2024-12-12 23:10:29 +01:00
// Dokka
// -> Register jar generation tasks
// See https://kotlinlang.org/docs/dokka-gradle.html#build-javadoc-jar
tasks.register<Jar>("dokkaHtmlJar") {
dependsOn(tasks.dokkaHtml)
from(tasks.dokkaHtml.flatMap { it.outputDirectory })
archiveClassifier.set("html-docs")
}
tasks.register<Jar>("dokkaJavadocJar") {
dependsOn(tasks.dokkaJavadoc)
from(tasks.dokkaJavadoc.flatMap { it.outputDirectory })
archiveClassifier.set("javadoc")
}
// -> Configure Dokka
tasks.withType<DokkaTask>().configureEach {
// Styling
val dokkaBaseConfiguration = """
{
"_customAssets": ["${file("assets/my-image.png")}"],
"_customStyleSheets": ["${file("assets/my-styles.css")}"],
"footerMessage": "&copy; 2024 The StarOpenSource Engine Authors. Licensed under the GNU Affero General Public License v3",
"_separateInheritedMembers": false,
"_templatesDir": "${file("dokka/templates")}",
"_mergeImplicitExpectActualDeclarations": false
}
"""
pluginsMapConfiguration = mapOf(
"org.jetbrains.dokka.base.DokkaBase" to dokkaBaseConfiguration
)
// Configuration
moduleName = rootProject.name
moduleVersion = "v" + rootProject.version as String
failOnWarning = true
suppressObviousFunctions = true
suppressInheritedMembers = true
dokkaSourceSets.configureEach {
// Metadata
displayName = project.name
documentedVisibilities = setOf(DokkaConfiguration.Visibility.PUBLIC, DokkaConfiguration.Visibility.PROTECTED)
reportUndocumented = false
skipEmptyPackages = false
skipDeprecated = false
jdkVersion = 21
// Source link
sourceLink {
localDirectory = projectDir.resolve("src")
remoteUrl = URI("https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/" + project.name.replace(":", "/") + "/src").toURL()
remoteLineSuffix = "#L"
}
}
}
2024-12-15 22:33:31 +01:00
2024-12-18 17:41:53 +01:00
// Git properties
// -> Configure
gitProperties {
dotGitDirectory = file("${rootProject.rootDir}/.git")
failOnNoGitDirectory = false // Allow continuing if .git directory is missing (tarball)
extProperty = "git"
2024-12-19 02:49:32 +01:00
dateFormat = "yyyy-MM-dd'T'HH:mm:ss.S'Z'"
2024-12-18 17:41:53 +01:00
dateFormatTimeZone = "UTC"
}
// -> Copy task
tasks.register("copyGitProperties") {
dependsOn(tasks.generateGitProperties)
inputs.file("${project.projectDir}/build/resources/main/git.properties")
2024-12-18 17:41:53 +01:00
doLast {
2024-12-19 02:52:37 +01:00
if (rootProject == project)
return@doLast
file(inputs.files.first())
.copyTo(
file("${project.projectDir}/src/main/resources/sosengine-${project.name.replace(":", "-")}-git.properties"),
overwrite = true
)
2024-12-15 22:33:31 +01:00
}
2024-12-18 17:41:53 +01:00
}
tasks.processResources {
dependsOn(tasks["copyGitProperties"])
}
// Gradle properties
// -> Copy task
tasks.register("copyGradleProperties") {
inputs.file("${project(":").projectDir.path}/gradle.properties")
2024-12-18 17:41:53 +01:00
doLast {
2024-12-19 02:52:37 +01:00
if (rootProject == project)
return@doLast
file(inputs.files.first())
.copyTo(
file("${project.projectDir}/src/main/resources/sosengine-${project.name.replace(":", "-")}-gradle.properties"),
overwrite = true
)
2024-12-18 17:41:53 +01:00
}
}
tasks.processResources {
dependsOn(tasks["copyGradleProperties"])
2024-12-15 22:33:31 +01:00
}
2024-12-12 23:10:29 +01:00
}