Skip to content

Commit

Permalink
chore: Move logic to handle version to build plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
hkupty committed Oct 22, 2024
1 parent d5dc2bd commit 1ae3741
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 3 deletions.
21 changes: 21 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
}

gradlePlugin {
plugins {
create("projectVersionPlugin") {
id = "penna.build.projectVersion"
implementationClass = "ProjectVersionPlugin"
}
}
}

dependencies {
implementation(gradleApi())
implementation(localGroovy())
}
1 change: 1 addition & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "build-logic"
30 changes: 30 additions & 0 deletions build-logic/src/main/kotlin/ProjectVersion.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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")
}
}
File renamed without changes.
1 change: 0 additions & 1 deletion gradle.properties

This file was deleted.

10 changes: 9 additions & 1 deletion penna-api/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 All @@ -20,6 +21,8 @@ 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 @@ -32,8 +35,13 @@ tasks.withType(JavaCompile).configureEach {
"-Xdoclint:all/public",
"-Werror"
]

dependsOn("projectVersion")
}


version = "0.8.1"

dependencies {
compileOnly libs.slf4j
compileOnly libs.jetbrains.annotations
Expand All @@ -50,4 +58,4 @@ jar {
manifest {
attributes('Implementation-Version': project.version)
}
}
}
4 changes: 4 additions & 0 deletions penna-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id 'java-library'
id 'penna.publishing'
id 'signing'
id 'penna.build.projectVersion'
id 'pmd'
id 'jvm-test-suite'
}
Expand Down Expand Up @@ -33,6 +34,9 @@ tasks.withType(JavaCompile).configureEach {
// TODO Eventually we should enable -Werror here
//"-Werror"
]

dependsOn("projectVersion")

}


Expand Down
5 changes: 4 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pluginManagement {
includeBuild('build-logic')

repositories {
gradlePluginPortal()
}
Expand All @@ -14,5 +16,6 @@ rootProject.name = 'penna'
include "penna-api"
include "penna-core"
// include "penna-perf"
include "penna-integration"
include "penna-yaml-config"
include 'sample'
include 'sample'
1 change: 1 addition & 0 deletions version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.8.1

0 comments on commit 1ae3741

Please sign in to comment.