Write and load version.properties for plugin (#1423)

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.
This commit is contained in:
Stef Tervelde
2026-02-10 01:25:49 +01:00
committed by GitHub
parent 21c2466f9d
commit 821d62c5e4
2 changed files with 16 additions and 1 deletions

View File

@@ -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")
}

View File

@@ -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?