Use buildSrc to deduplicate build logic (#262)
This commit is contained in:
@@ -2,31 +2,31 @@ plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
val preload by creating {
|
||||
this.java {
|
||||
srcDir("src/preload/kotlin")
|
||||
}
|
||||
}
|
||||
val main by getting
|
||||
}
|
||||
val preload: SourceSet by sourceSets.creating
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
|
||||
val openrndrVersion =
|
||||
(findProperty("OPENRNDR.version")?.toString() ?: System.getenv("OPENRNDR_VERSION"))?.replace("v", "")
|
||||
val openrndrVersion: String =
|
||||
(extra.properties["OPENRNDR.version"] as String? ?: System.getenv("OPENRNDR_VERSION"))?.removePrefix("v")
|
||||
?: "0.5.1-SNAPSHOT"
|
||||
|
||||
configurations.all {
|
||||
resolutionStrategy.eachDependency {
|
||||
if (requested.group == "org.openrndr") useVersion(openrndrVersion)
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.20")
|
||||
implementation("org.jetbrains.kotlin:kotlin-serialization:1.6.20")
|
||||
val preloadImplementation by configurations.getting
|
||||
preloadImplementation("org.openrndr:openrndr-application:$openrndrVersion")
|
||||
preloadImplementation("org.openrndr:openrndr-extensions:$openrndrVersion")
|
||||
implementation(libs.kotlin.gradle.plugin)
|
||||
implementation(libs.dokka.gradle.plugin)
|
||||
implementation(libs.kotlin.serialization.gradle.plugin)
|
||||
// https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
|
||||
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
|
||||
"preloadImplementation"(libs.openrndr.application)
|
||||
"preloadImplementation"(libs.openrndr.extensions)
|
||||
}
|
||||
|
||||
tasks.getByName("compileKotlin").dependsOn("compilePreloadKotlin")
|
||||
7
buildSrc/settings.gradle.kts
Normal file
7
buildSrc/settings.gradle.kts
Normal file
@@ -0,0 +1,7 @@
|
||||
dependencyResolutionManagement {
|
||||
versionCatalogs {
|
||||
create("libs") {
|
||||
from(files("../gradle/libs.versions.toml"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.openrndr.extra.convention
|
||||
|
||||
import org.gradle.api.artifacts.CacheableRule
|
||||
import org.gradle.api.artifacts.ComponentMetadataContext
|
||||
import org.gradle.api.artifacts.ComponentMetadataRule
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.kotlin.dsl.named
|
||||
import org.gradle.nativeplatform.MachineArchitecture
|
||||
import org.gradle.nativeplatform.OperatingSystemFamily
|
||||
import javax.inject.Inject
|
||||
|
||||
@CacheableRule
|
||||
abstract class FFmpegRule : ComponentMetadataRule {
|
||||
val jvmNativeVariants: List<JvmNativeVariant> = listOf(
|
||||
JvmNativeVariant("linux-arm64", OperatingSystemFamily.LINUX, "arm64"),
|
||||
JvmNativeVariant("linux-x86_64", OperatingSystemFamily.LINUX, "x86-64"),
|
||||
JvmNativeVariant("macos-arm64", OperatingSystemFamily.MACOS, "arm64"),
|
||||
JvmNativeVariant("macos-x86_64", OperatingSystemFamily.MACOS, "x86-64"),
|
||||
JvmNativeVariant("windows-x86_64", OperatingSystemFamily.WINDOWS, "x86-64")
|
||||
)
|
||||
|
||||
@get:Inject
|
||||
abstract val objects: ObjectFactory
|
||||
|
||||
override fun execute(context: ComponentMetadataContext) = context.details.run {
|
||||
withVariant("runtime") {
|
||||
attributes {
|
||||
attributes.attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named("none"))
|
||||
attributes.attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named("none"))
|
||||
}
|
||||
}
|
||||
for ((targetName, os, arch) in jvmNativeVariants) {
|
||||
addVariant("$targetName-runtime", "runtime") {
|
||||
attributes {
|
||||
attributes.attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named(os))
|
||||
attributes.attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named(arch))
|
||||
}
|
||||
withFiles {
|
||||
addFile("${id.name}-${id.version}-$targetName.jar")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.openrndr.extra.convention
|
||||
|
||||
import org.gradle.api.artifacts.CacheableRule
|
||||
import org.gradle.api.artifacts.ComponentMetadataContext
|
||||
import org.gradle.api.artifacts.ComponentMetadataRule
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.kotlin.dsl.named
|
||||
import org.gradle.nativeplatform.MachineArchitecture
|
||||
import org.gradle.nativeplatform.OperatingSystemFamily
|
||||
import javax.inject.Inject
|
||||
|
||||
@CacheableRule
|
||||
abstract class LwjglRule : ComponentMetadataRule {
|
||||
val jvmNativeVariants: List<JvmNativeVariant> = listOf(
|
||||
JvmNativeVariant("natives-linux-arm64", OperatingSystemFamily.LINUX, "arm64"),
|
||||
JvmNativeVariant("natives-linux", OperatingSystemFamily.LINUX, "x86-64"),
|
||||
JvmNativeVariant("natives-macos-arm64", OperatingSystemFamily.MACOS, "arm64"),
|
||||
JvmNativeVariant("natives-macos", OperatingSystemFamily.MACOS, "x86-64"),
|
||||
JvmNativeVariant("natives-windows", OperatingSystemFamily.WINDOWS, "x86-64")
|
||||
)
|
||||
|
||||
@get:Inject
|
||||
abstract val objects: ObjectFactory
|
||||
|
||||
override fun execute(context: ComponentMetadataContext) = context.details.run {
|
||||
if (id.group != "org.lwjgl") return
|
||||
if (id.name == "lwjgl-egl") return
|
||||
withVariant("runtime") {
|
||||
attributes {
|
||||
attributes.attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named("none"))
|
||||
attributes.attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named("none"))
|
||||
}
|
||||
}
|
||||
for ((targetName, os, arch) in jvmNativeVariants) {
|
||||
addVariant("$targetName-runtime", "runtime") {
|
||||
attributes {
|
||||
attributes.attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named(os))
|
||||
attributes.attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named(arch))
|
||||
}
|
||||
withFiles {
|
||||
addFile("${id.name}-${id.version}-$targetName.jar")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.openrndr.extra.convention
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.get
|
||||
import org.gradle.kotlin.dsl.named
|
||||
import org.gradle.nativeplatform.MachineArchitecture
|
||||
import org.gradle.nativeplatform.OperatingSystemFamily
|
||||
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
|
||||
data class JvmNativeVariant(val targetName: String, val os: String, val arch: String)
|
||||
|
||||
val currentOperatingSystemName: String = DefaultNativePlatform.getCurrentOperatingSystem().toFamilyName()
|
||||
val currentArchitectureName: String = DefaultNativePlatform.getCurrentArchitecture().name
|
||||
|
||||
fun Project.addHostMachineAttributesToRuntimeConfigurations() {
|
||||
configurations.matching {
|
||||
it.name.endsWith("runtimeClasspath", ignoreCase = true)
|
||||
}.configureEach {
|
||||
attributes {
|
||||
attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named(currentOperatingSystemName))
|
||||
attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named(currentArchitectureName))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.openrndr.extra.convention
|
||||
|
||||
addHostMachineAttributesToRuntimeConfigurations()
|
||||
|
||||
val openrndrVersion: String =
|
||||
(extra.properties["OPENRNDR.version"] as String? ?: System.getenv("OPENRNDR_VERSION"))?.removePrefix("v")
|
||||
?: "0.5.1-SNAPSHOT"
|
||||
|
||||
configurations.all {
|
||||
resolutionStrategy.eachDependency {
|
||||
if (requested.group == "org.openrndr") useVersion(openrndrVersion)
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
components {
|
||||
all<LwjglRule>()
|
||||
withModule<FFmpegRule>("org.bytedeco:javacpp")
|
||||
withModule<FFmpegRule>("org.bytedeco:ffmpeg")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.openrndr.extra.convention
|
||||
|
||||
import org.jetbrains.dokka.gradle.DokkaTaskPartial
|
||||
import java.net.URL
|
||||
|
||||
plugins {
|
||||
id("org.jetbrains.dokka")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
tasks.withType<DokkaTaskPartial>() {
|
||||
dokkaSourceSets {
|
||||
configureEach {
|
||||
skipDeprecated.set(true)
|
||||
val sourcesDirectory = try {
|
||||
file("src/$name/kotlin", PathValidation.EXISTS)
|
||||
} catch (_: InvalidUserDataException) {
|
||||
return@configureEach
|
||||
}
|
||||
// Specifies the location of the project source code on the Web.
|
||||
// If provided, Dokka generates "source" links for each declaration.
|
||||
sourceLink {
|
||||
// Unix based directory relative path to the root of the project (where you execute gradle respectively).
|
||||
localDirectory.set(sourcesDirectory)
|
||||
// URL showing where the source code can be accessed through the web browser
|
||||
remoteUrl.set(
|
||||
URL("https://github.com/openrndr/orx/blob/master/${moduleName.get()}/src/$name/kotlin")
|
||||
)
|
||||
// Suffix which is used to append the line number to the URL. Use #L for GitHub
|
||||
remoteLineSuffix.set("#L")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package org.openrndr.extra.convention
|
||||
|
||||
import org.gradle.accessors.dm.LibrariesForLibs
|
||||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import java.net.URI
|
||||
|
||||
val libs = the<LibrariesForLibs>()
|
||||
|
||||
plugins {
|
||||
java
|
||||
kotlin("jvm")
|
||||
id("maven-publish")
|
||||
id("org.openrndr.extra.convention.component-metadata-rule")
|
||||
id("org.openrndr.extra.convention.dokka")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
// This is needed to resolve `com.github.ricardomatias:delaunator`
|
||||
url = URI("https://maven.openrndr.org")
|
||||
}
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
group = "org.openrndr.extra"
|
||||
|
||||
val main by sourceSets.getting
|
||||
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val demo by sourceSets.creating
|
||||
|
||||
dependencies {
|
||||
implementation(libs.kotlin.stdlib)
|
||||
implementation(libs.kotlin.logging)
|
||||
testImplementation(libs.kotlin.test)
|
||||
"demoImplementation"(main.output.classesDirs + main.runtimeClasspath)
|
||||
"demoImplementation"(libs.openrndr.application)
|
||||
"demoImplementation"(libs.openrndr.extensions)
|
||||
"demoRuntimeOnly"(libs.openrndr.gl3.core)
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain {
|
||||
this as JavaToolchainSpec
|
||||
languageVersion.set(JavaLanguageVersion.of(libs.versions.jvmTarget.get()))
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val test by getting(Test::class) {
|
||||
useJUnitPlatform()
|
||||
testLogging.exceptionFormat = TestExceptionFormat.FULL
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val javadoc by getting(Javadoc::class) {
|
||||
options {
|
||||
this as StandardJavadocDocletOptions
|
||||
addBooleanOption("Xdoclint:none", true)
|
||||
}
|
||||
}
|
||||
withType<KotlinCompile>() {
|
||||
kotlinOptions.apiVersion = libs.versions.kotlinApi.get()
|
||||
kotlinOptions.languageVersion = libs.versions.kotlinLanguage.get()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package org.openrndr.extra.convention
|
||||
|
||||
import org.gradle.accessors.dm.LibrariesForLibs
|
||||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import java.net.URI
|
||||
|
||||
val libs = the<LibrariesForLibs>()
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
id("maven-publish")
|
||||
id("org.openrndr.extra.convention.component-metadata-rule")
|
||||
id("org.openrndr.extra.convention.dokka")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
// This is needed to resolve `com.github.ricardomatias:delaunator`
|
||||
url = URI("https://maven.openrndr.org")
|
||||
}
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
group = "org.openrndr.extra"
|
||||
|
||||
tasks.withType<KotlinCompile>() {
|
||||
kotlinOptions.apiVersion = libs.versions.kotlinApi.get()
|
||||
kotlinOptions.languageVersion = libs.versions.kotlinLanguage.get()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvm {
|
||||
jvmToolchain {
|
||||
this as JavaToolchainSpec
|
||||
languageVersion.set(JavaLanguageVersion.of(libs.versions.jvmTarget.get()))
|
||||
}
|
||||
compilations {
|
||||
val main by getting
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val demo by creating {
|
||||
defaultSourceSet {
|
||||
dependencies {
|
||||
implementation(main.output.allOutputs)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
testRuns["test"].executionTask {
|
||||
useJUnitPlatform()
|
||||
testLogging.exceptionFormat = TestExceptionFormat.FULL
|
||||
}
|
||||
}
|
||||
|
||||
js(IR) {
|
||||
browser()
|
||||
nodejs()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val commonMain by getting {
|
||||
dependencies {
|
||||
implementation(libs.kotlin.stdlib)
|
||||
implementation(libs.kotlin.logging)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val commonTest by getting {
|
||||
dependencies {
|
||||
implementation(libs.kotlin.test)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val jvmTest by getting {
|
||||
dependencies {
|
||||
runtimeOnly(libs.bundles.jupiter)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val jvmDemo by getting {
|
||||
dependencies {
|
||||
implementation(libs.openrndr.application)
|
||||
implementation(libs.openrndr.extensions)
|
||||
runtimeOnly(libs.openrndr.gl3.core)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user