Skip to content

Commit 821d62c

Browse files
authored
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.
1 parent 21c2466 commit 821d62c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

java/gradle/build.gradle.kts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,16 @@ publishing{
3838
url = uri(project(":app").layout.buildDirectory.dir("resources-bundled/common/repository").get().asFile.absolutePath)
3939
}
4040
}
41+
}
42+
43+
tasks.register("writeVersion") {
44+
// make the version available to the plugin at runtime by writing it to a properties file in the resources directory
45+
doLast {
46+
val file = layout.buildDirectory.file("resources/main/version.properties").get().asFile
47+
file.parentFile.mkdirs()
48+
file.writeText("version=${project.version}")
49+
}
50+
}
51+
tasks.named("processResources") {
52+
dependsOn("writeVersion")
4153
}

java/gradle/src/main/kotlin/ProcessingPlugin.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ class ProcessingPlugin @Inject constructor(private val objectFactory: ObjectFact
2020
val sketchName = project.layout.projectDirectory.asFile.name.replace(Regex("[^a-zA-Z0-9_]"), "_")
2121

2222
val isProcessing = project.findProperty("processing.version") != null
23-
val processingVersion = project.findProperty("processing.version") as String? ?: "4.3.4"
23+
val processingVersion = project.findProperty("processing.version") as String?
24+
?: javaClass.classLoader.getResourceAsStream("version.properties")?.use { stream ->
25+
java.util.Properties().apply { load(stream) }.getProperty("version")
26+
} ?: "4.3.4"
2427
val processingGroup = project.findProperty("processing.group") as String? ?: "org.processing"
2528
val workingDir = project.findProperty("processing.workingDir") as String?
2629
val debugPort = project.findProperty("processing.debugPort") as String?

0 commit comments

Comments
 (0)