Add publish-library convention plugin

This commit is contained in:
Edwin Jakobs
2025-09-15 20:49:05 +02:00
parent a0b7df5585
commit f8cc9b713e
5 changed files with 68 additions and 5 deletions

View File

@@ -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) 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=<platform>`, where `<platform>` is either `windows`, `macos`, `linux-x64`, or `linux-arm64`.
## Updating OPENRNDR, ORX and other dependencies ## 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 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. 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.

View File

@@ -5,7 +5,8 @@ plugins {
alias(libs.plugins.kotlin.serialization) alias(libs.plugins.kotlin.serialization)
id("conventions.kotlin-jvm") id("conventions.kotlin-jvm")
id("conventions.openrndr-tasks") id("conventions.openrndr-tasks")
id("conventions.distribution") // id("conventions.distribute-application")
id("conventions.publish-library")
} }
dependencies { dependencies {
@@ -13,6 +14,9 @@ dependencies {
implementation(openrndr.draw) implementation(openrndr.draw)
runtimeOnly(openrndr.gl3) runtimeOnly(openrndr.gl3)
implementation(openrndr.dialogs)
implementation(openrndr.orextensions)
implementation(openrndr.ffmpeg) implementation(openrndr.ffmpeg)
implementation(orx.bundles.basic) implementation(orx.bundles.basic)
implementation(orx.olive) implementation(orx.olive)

View File

@@ -11,6 +11,18 @@ dependencyResolutionManagement {
create("libs") { create("libs") {
from(files("../gradle/libs.versions.toml")) 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")
}
} }
} }

View File

@@ -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<VersionCatalogsExtension>().named("libs")
val openrndr = extensions.getByType<VersionCatalogsExtension>().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<MavenPublication>("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")
}
}
}