Skip to content

Commit

Permalink
chore: Evaluate the version immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
hkupty committed Oct 22, 2024
1 parent 1ae3741 commit 9ee8d46
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 30 deletions.
33 changes: 10 additions & 23 deletions build-logic/src/main/kotlin/ProjectVersion.kt
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
import org.gradle.api.DefaultTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.register
import kotlin.io.path.readBytes

abstract class ProjectVersion : DefaultTask() {
@TaskAction
fun action() {
try {
val version =
project.rootDir
.toPath()
.resolve("version")
.readBytes()
.toString(Charsets.UTF_8)
logger.info("Read $version")
project.version = version
} catch (ex: Exception) {
logger.warn("Unable to fetch version because of exception", ex)
}
}
}

class ProjectVersionPlugin : Plugin<Project> {
override fun apply(target: Project) {
target.tasks.register<ProjectVersion>("projectVersion")
override fun apply(project: Project) {
val version =
project.rootDir
.toPath()
.resolve("version")
.readBytes()
.toString(Charsets.UTF_8)
project.getLogger().info("Read $version")
project.version = version
project.setProperty("version", version)
}
}
6 changes: 1 addition & 5 deletions penna-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ java {
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true

dependsOn("projectVersion")
}

// The API is an optional client-facing library and therefore it should not have gaps
Expand All @@ -35,12 +33,10 @@ tasks.withType(JavaCompile).configureEach {
"-Xdoclint:all/public",
"-Werror"
]

dependsOn("projectVersion")
}


version = "0.8.1"
// version = "0.8.1"

dependencies {
compileOnly libs.slf4j
Expand Down
2 changes: 0 additions & 2 deletions penna-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ tasks.withType(JavaCompile).configureEach {
//"-Werror"
]

dependsOn("projectVersion")

}


Expand Down
1 change: 1 addition & 0 deletions penna-yaml-config/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'java-library'
id 'penna.publishing'
id 'penna.build.projectVersion'
id 'pmd'
}

Expand Down

0 comments on commit 9ee8d46

Please sign in to comment.