Skip to content

Commit

Permalink
Update build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Aug 28, 2024
1 parent 6990cc2 commit 3a9e695
Show file tree
Hide file tree
Showing 23 changed files with 337 additions and 256 deletions.
229 changes: 4 additions & 225 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,119 +1,22 @@
import org.gradle.plugins.ide.idea.model.IdeaModel

plugins {
`java-platform`
`maven-publish`
signing
}

val projGroupId: String by project
val projArtifactId: String by project
val projName: String by project
val projVersion: String by project
val projVcs: String by project
val projBranch: String by project
val projLicenseYear: String by project
val projLicenseFileName: String by project
val orgName: String by project
val orgUrl: String by project

val jdkVersion: String by rootProject
val jdkEnablePreview: String by rootProject
val jdkEarlyAccessDoc: String? by rootProject
val kotlinTargetJdkVersion: String by rootProject

val targetJavaVersion = jdkVersion.toInt()

group = projGroupId
version = projVersion

val artifactNameMap = buildMap {
Artifact.values().forEach { put(it.subprojectName, it.artifactName) }
put(":samples", "overrungl-samples")
}

artifactNameMap.forEach { (subprojectName, artifactName) ->
project(subprojectName) {
apply(plugin = "java-library")
apply(plugin = "idea")

group = projGroupId
version = projVersion

repositories {
mavenCentral()
// temporary maven repositories
maven { url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") }
maven { url = uri("https://s01.oss.sonatype.org/content/repositories/releases") }
}

val compileOnly by configurations
dependencies {
compileOnly("org.jetbrains:annotations:24.1.0")
if (project.name != "core") {
compileOnly(project(Artifact.CORE.subprojectName))
constraints { api("io.github.over-run:overrungl:$projVersion") }
}
}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
if (jdkEnablePreview.toBoolean()) options.compilerArgs.add("--enable-preview")
options.release.set(targetJavaVersion)
}

tasks.withType<Test> {
if (jdkEnablePreview.toBoolean()) jvmArgs("--enable-preview")
}

extensions.configure<JavaPluginExtension>("java") {
toolchain.languageVersion.set(JavaLanguageVersion.of(targetJavaVersion))
withJavadocJar()
withSourcesJar()
}

tasks.named<Jar>("jar") {
manifestContentCharset = "utf-8"
metadataCharset = "utf-8"
manifest.attributes(
"Specification-Title" to projName,
"Specification-Vendor" to "Overrun Organization",
"Specification-Version" to projVersion.split('.', limit = 2)[0],
"Implementation-Title" to projName,
"Implementation-Vendor" to "Overrun Organization",
"Implementation-Version" to projVersion
)
archiveBaseName.set(artifactName)
from(rootProject.file(projLicenseFileName)).rename(
projLicenseFileName,
"${projLicenseFileName}_$artifactName"
)
}

tasks.named<Jar>("sourcesJar") {
dependsOn(tasks["classes"])
archiveBaseName.set(artifactName)
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
}

tasks.named<Jar>("javadocJar") {
val javadoc by tasks
dependsOn(javadoc)
archiveBaseName.set(artifactName)
archiveClassifier.set("javadoc")
from(javadoc)
}

artifacts {
archives(tasks["sourcesJar"])
archives(tasks["javadocJar"])
}

the<IdeaModel>().module.inheritOutputDirs = true
}
}

allprojects {
tasks.withType<Javadoc> {
options {
Expand Down Expand Up @@ -144,145 +47,27 @@ allprojects {
)

bottom =
"<a href=\"https://github.com/Over-Run/overrungl/issues\">Report a bug or suggest an enhancement</a><br>" +
"Copyright © 2022-$projLicenseYear Overrun Organization<br>" +
"<b>$projVersion</b>"
"""<a href="https://github.com/Over-Run/overrungl/issues">Report a bug or suggest an enhancement</a><br>""" +
"Copyright © $projLicenseYear Overrun Organization<br>" +
"<b>$projVersion (env ${Runtime.version()})</b>"
}
}
encoding = "UTF-8"
locale = "en_US"
windowTitle = "OverrunGL $projVersion"
jFlags("-Duser.language=en-US")
}
title = "OverrunGL $projVersion"
isFailOnError = false
}
}

Artifact.values().forEach {
project(it.subprojectName) {
val javaComponent = components.findByName("java") as AdhocComponentWithVariants
// Add a different runtime variant for each platform
it.nativeBinding?.platforms?.forEach { platform ->
val nativeFileName = it.nativeFileName(platform)
val file = File("${rootProject.projectDir}/natives/$nativeFileName")

if (file.exists()) {
val archiveTaskName = "${it.nativeBinding?.bindingName}${platform.classifier}Jar"

val nativeJar = tasks.register<Jar>(archiveTaskName) {
archiveBaseName.set(it.artifactName)
archiveClassifier.set(platform.classifier)
from(file) { into(File(nativeFileName).parent) }
}

val nativeRuntimeElements = configurations.create(platform.classifier + "RuntimeElements") {
isCanBeConsumed = true; isCanBeResolved = false
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, targetJavaVersion)
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements.JAR))
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
attributes.attribute(
OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE,
objects.named(platform.osFamilyName)
)
attributes.attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named(platform.osArch))
}
outgoing.artifact(tasks.named("jar"))
outgoing.artifact(nativeJar)
extendsFrom(configurations["runtimeElements"])
}
javaComponent.addVariantsFromConfiguration(nativeRuntimeElements) {}
}
}
}
}

publishing.publications {
fun MavenPom.setupPom(pomName: String, pomDescription: String, pomPackaging: String) {
name.set(pomName)
description.set(pomDescription)
url.set("https://github.com/$projVcs")
packaging = pomPackaging
licenses {
license {
name.set("MIT")
url.set("https://raw.githubusercontent.com/$projVcs/$projBranch/LICENSE")
}
}
organization {
name.set(orgName)
url.set(orgUrl)
}
developers {
developer {
id = "squid233"
url = "https://github.com/squid233"
organization = orgName
organizationUrl = orgUrl
}
}
scm {
connection.set("scm:git:https://github.com/${projVcs}.git")
developerConnection.set("scm:git:https://github.com/${projVcs}.git")
url.set("https://github.com/${projVcs}.git")
}
}

Artifact.values().forEach { module ->
create<MavenPublication>("maven${module.name}") {
groupId = projGroupId
artifactId = module.artifactName
version = projVersion
description = module.projectDescription
from(project(module.subprojectName).components["java"])
pom {
setupPom(module.projectName, module.projectDescription, "jar")
}
}
}

create<MavenPublication>("overrunglBOM") {
from(components["javaPlatform"])
artifactId = "overrungl-bom"
pom {
fun org.w3c.dom.Node.appendBOM(platform: NativePlatform?, module: Artifact) {
ownerDocument.createElement("dependency").also(::appendChild).apply {
appendChild(
ownerDocument.createElement("groupId").also(::appendChild)
.apply { textContent = "io.github.over-run" })
appendChild(
ownerDocument.createElement("artifactId").also(::appendChild)
.apply { textContent = module.artifactName })
appendChild(
ownerDocument.createElement("version").also(::appendChild)
.apply { textContent = projVersion })
if (platform != null) {
appendChild(
ownerDocument.createElement("classifier").also(::appendChild)
.apply { textContent = platform.classifier })
}
}
}

setupPom("OverrunGL BOM", "OverrunGL Bill of Materials.", "pom")
withXml {
asElement().getElementsByTagName("dependencyManagement").item(0).apply {
asElement().getElementsByTagName("dependencies").item(0).apply {
Artifact.values().forEach { module ->
if (module.nativeBinding != null) {
module.nativeBinding!!.platforms.forEach { appendBOM(it, module) }
} else {
appendBOM(null, module)
}
}
}
}

// Workaround for https://github.com/gradle/gradle/issues/7529
asNode()
}
}
}
}
Expand Down Expand Up @@ -310,9 +95,3 @@ signing {
if (!projVersion.endsWith("-SNAPSHOT") && System.getProperty("gpg.signing", "true").toBoolean())
sign(publishing.publications)
}

dependencies {
constraints {
Artifact.values().forEach { api("io.github.over-run:${it.artifactName}:$projVersion") }
}
}
12 changes: 12 additions & 0 deletions buildSrc/src/main/kotlin/OverrunGLModuleExtension.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider

/**
* @author squid233
* @since 0.1.0
*/
abstract class OverrunGLModuleExtension {
abstract val artifactName: Property<String>
abstract val publishInfo: Property<Artifact>
abstract val nativeBinding: Property<NativeBinding>
}
8 changes: 8 additions & 0 deletions buildSrc/src/main/kotlin/accessors.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import org.gradle.api.Action
import org.gradle.api.Project

val Project.overrunglModule: OverrunGLModuleExtension
get() = extensions.getByName("overrunglModule") as OverrunGLModuleExtension

fun Project.overrunglModule(configure: Action<OverrunGLModuleExtension>) =
extensions.configure("overrunglModule", configure)
Loading

0 comments on commit 3a9e695

Please sign in to comment.