From 2a2897e6e6822d1794304fb2b9798bd61e3093ac Mon Sep 17 00:00:00 2001 From: Stef Tervelde Date: Sun, 8 Feb 2026 09:52:09 +0100 Subject: [PATCH] Write and load version.properties for plugin Add a writeVersion Gradle task that writes project.version to build/resources/main/version.properties, so the plugin can access the project version at runtime. This way the version number of the plugin and the used version of processing.core will be the same. --- java/gradle/build.gradle.kts | 12 ++++++++++++ java/gradle/src/main/kotlin/ProcessingPlugin.kt | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/java/gradle/build.gradle.kts b/java/gradle/build.gradle.kts index 0171384f4..b5718a890 100644 --- a/java/gradle/build.gradle.kts +++ b/java/gradle/build.gradle.kts @@ -38,4 +38,16 @@ publishing{ url = uri(project(":app").layout.buildDirectory.dir("resources-bundled/common/repository").get().asFile.absolutePath) } } +} + +tasks.register("writeVersion") { + // make the version available to the plugin at runtime by writing it to a properties file in the resources directory + doLast { + val file = layout.buildDirectory.file("resources/main/version.properties").get().asFile + file.parentFile.mkdirs() + file.writeText("version=${project.version}") + } +} +tasks.named("processResources") { + dependsOn("writeVersion") } \ No newline at end of file diff --git a/java/gradle/src/main/kotlin/ProcessingPlugin.kt b/java/gradle/src/main/kotlin/ProcessingPlugin.kt index df558710f..375b17549 100644 --- a/java/gradle/src/main/kotlin/ProcessingPlugin.kt +++ b/java/gradle/src/main/kotlin/ProcessingPlugin.kt @@ -20,7 +20,10 @@ class ProcessingPlugin @Inject constructor(private val objectFactory: ObjectFact val sketchName = project.layout.projectDirectory.asFile.name.replace(Regex("[^a-zA-Z0-9_]"), "_") val isProcessing = project.findProperty("processing.version") != null - val processingVersion = project.findProperty("processing.version") as String? ?: "4.3.4" + val processingVersion = project.findProperty("processing.version") as String? + ?: javaClass.classLoader.getResourceAsStream("version.properties")?.use { stream -> + java.util.Properties().apply { load(stream) }.getProperty("version") + } ?: "4.3.4" val processingGroup = project.findProperty("processing.group") as String? ?: "org.processing" val workingDir = project.findProperty("processing.workingDir") as String? val debugPort = project.findProperty("processing.debugPort") as String?