From f8cc9b713e68c6870973f2639ae84b6950a3e809 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Mon, 15 Sep 2025 20:49:05 +0200 Subject: [PATCH] Add publish-library convention plugin --- README.md | 9 ++-- build.gradle.kts | 6 ++- buildSrc/settings.gradle.kts | 12 +++++ ....kts => distribute-application.gradle.kts} | 0 .../conventions/publish-library.gradle.kts | 46 +++++++++++++++++++ 5 files changed, 68 insertions(+), 5 deletions(-) rename buildSrc/src/main/kotlin/conventions/{distribution.gradle.kts => distribute-application.gradle.kts} (100%) create mode 100644 buildSrc/src/main/kotlin/conventions/publish-library.gradle.kts diff --git a/README.md b/README.md index 63c31f4..b2d5457 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,6 @@ You will find some [basic instructions](https://guide.openrndr.org/setUpYourFirs See the [wiki](https://github.com/openrndr/openrndr-template/wiki) -## Cross builds - -To create a runnable jar for a platform different from your current platform, use `./gradlew jar -PtargetPlatform=`, where `` is either `windows`, `macos`, `linux-x64`, or `linux-arm64`. - ## Updating OPENRNDR, ORX and other dependencies The openrndr-template depends on various packages including the core [openrndr](https://github.com/openrndr/openrndr/) and the [orx](https://github.com/openrndr/orx/) extensions and @@ -64,3 +60,8 @@ any time a commit is tagged with a version number like `v1.*`. For example, we c ``` You can follow the progress of the action under the Actions tab in GitHub. Once complete, the executables will appear under the Releases section. + +## Building libraries + +This template can be used to create library projects. In [build.gradle.kts](build.gradle.kts) one removes the `convention.distribute-application` plugin and adds the `convention.publish-library` plugin. This automatically +sets up the `maven-publish` plugin, which adds the `publishToMavenLocal` task. The plugin also adds a `demo` sourceSet with runtime dependencies set to go. Demos can be placed in `src/demo/kotlin` and started right away. diff --git a/build.gradle.kts b/build.gradle.kts index bbe4734..0281c75 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,8 @@ plugins { alias(libs.plugins.kotlin.serialization) id("conventions.kotlin-jvm") id("conventions.openrndr-tasks") - id("conventions.distribution") +// id("conventions.distribute-application") + id("conventions.publish-library") } dependencies { @@ -13,6 +14,9 @@ dependencies { implementation(openrndr.draw) runtimeOnly(openrndr.gl3) + implementation(openrndr.dialogs) + implementation(openrndr.orextensions) + implementation(openrndr.ffmpeg) implementation(orx.bundles.basic) implementation(orx.olive) diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index a934a7c..5c670cd 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -11,6 +11,18 @@ dependencyResolutionManagement { create("libs") { from(files("../gradle/libs.versions.toml")) } + // We use a regex to get the openrndr/orx versions from the primary catalog as there is no public Gradle API to parse catalogs. + val orRegEx = Regex("^openrndr[ ]*=[ ]*(?:\\{[ ]*require[ ]*=[ ]*)?\"(.*)\"[ ]*(?:\\})?", RegexOption.MULTILINE) + val orxRegEx = Regex("^orx[ ]*=[ ]*(?:\\{[ ]*require[ ]*=[ ]*)?\"(.*)\"[ ]*(?:\\})?", RegexOption.MULTILINE) + val openrndrVersion = orRegEx.find(File(rootDir,"../gradle/libs.versions.toml").readText())?.groupValues?.get(1) ?: error("can't find openrndr version") + val orxVersion = orxRegEx.find(File(rootDir,"../gradle/libs.versions.toml").readText())?.groupValues?.get(1) ?: error("can't find orx version") + + create("orx") { + from("org.openrndr.extra:orx-module-catalog:$orxVersion") + } + create("openrndr") { + from("org.openrndr:openrndr-module-catalog:$openrndrVersion") + } } } diff --git a/buildSrc/src/main/kotlin/conventions/distribution.gradle.kts b/buildSrc/src/main/kotlin/conventions/distribute-application.gradle.kts similarity index 100% rename from buildSrc/src/main/kotlin/conventions/distribution.gradle.kts rename to buildSrc/src/main/kotlin/conventions/distribute-application.gradle.kts diff --git a/buildSrc/src/main/kotlin/conventions/publish-library.gradle.kts b/buildSrc/src/main/kotlin/conventions/publish-library.gradle.kts new file mode 100644 index 0000000..33bb4b4 --- /dev/null +++ b/buildSrc/src/main/kotlin/conventions/publish-library.gradle.kts @@ -0,0 +1,46 @@ +package conventions + +import org.gradle.kotlin.dsl.java +import org.gradle.kotlin.dsl.kotlin + +plugins { + java + kotlin("jvm") + `maven-publish` + +} + +val libs = extensions.getByType().named("libs") +val openrndr = extensions.getByType().named("openrndr") + +val demo = sourceSets.create("demo") + +val main = sourceSets.getByName("main") +val mainImplementation = project.configurations.getByName(main.implementationConfigurationName) + + +val demoImplementation = project.configurations.getByName(demo.implementationConfigurationName) +//demoImplementation.dependencies.addAll(mainImplementation.dependencies) +// +//val demo by sourceSets.creating { +// +// +//} +demoImplementation.extendsFrom(mainImplementation) + +dependencies { + "demoRuntimeOnly"(openrndr.findLibrary("gl3").get()) +} + +publishing { + publications { + create("maven") { + from(components["java"]) + groupId = property("project.group")?.toString() ?: error("project.group not set") + artifactId = property("project.name")?.toString() ?: error("project.name not set") + description = property("project.name")?.toString() ?: error("project.name not set") + version = property("project.version")?.toString() ?: error("project.version not set") + + } + } +} \ No newline at end of file