Skip to content

Commit

Permalink
Merge pull request #131 from kitakkun/refactor_buildscripts
Browse files Browse the repository at this point in the history
Refactor buildscripts
  • Loading branch information
kitakkun authored Dec 8, 2024
2 parents 6169905 + f75fe17 commit 30e0d35
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 174 deletions.
26 changes: 0 additions & 26 deletions build-logic/convention/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions build-logic/settings.gradle.kts

This file was deleted.

3 changes: 3 additions & 0 deletions gradle-conventions-settings/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
`kotlin-dsl`
}
3 changes: 3 additions & 0 deletions gradle-conventions-settings/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rootProject.name = "gradle-conventions-settings"

apply(from = "src/main/kotlin/settings-conventions.settings.gradle.kts")
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import java.nio.file.Files
import java.nio.file.Path

/**
* This buildscript can be applied with id "settings-conventions" in plugins block.
* (note that you need to includeBuild before use it)
*
* This file is written referencing kotlinx-rpc project:
* https://github.com/Kotlin/kotlinx-rpc/blob/main/gradle-conventions-settings/src/main/kotlin/settings-conventions.settings.gradle.kts
*/

pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
google()
}
}

dependencyResolutionManagement {
repositories {
mavenCentral()
gradlePluginPortal()
google()
}

versionCatalogs {
create("libs") {
val globalRootPath = findGlobalRootPath(rootDir.toPath())
from(files("$globalRootPath/versions-root/libs.versions.toml"))
System.getenv("KOTLIN_VERSION")?.let { version("kotlin", it) }
}
}
}

/**
* This plugin will be applied to all modules in the rootProject.
* So, $rootProject doesn't always represents root directory for this repository.
* We need to traverse directories until we find "versions-root" directory.
*/
fun findGlobalRootPath(start: Path): Path {
var path = start

while (
Files.newDirectoryStream(path).use { it.toList() }.none {
Files.isDirectory(it) && it.fileName.toString() == "versions-root"
}
) {
path = path.parent ?: error("Unable to find root path for Kondition project.")
}

return path
}
7 changes: 7 additions & 0 deletions gradle-conventions-settings/src/main/kotlin/util/Project.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package util

import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType

val Project.libs get() = extensions.getByType<VersionCatalogsExtension>().named("libs")
9 changes: 9 additions & 0 deletions gradle-conventions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
`kotlin-dsl`
}

dependencies {
implementation(":gradle-conventions-settings")
compileOnly(libs.ktlint.gradle)
compileOnly(libs.maven.publish)
}
9 changes: 9 additions & 0 deletions gradle-conventions/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rootProject.name = "gradle-conventions"

pluginManagement {
includeBuild("../gradle-conventions-settings")
}

plugins {
id("settings-conventions")
}
15 changes: 15 additions & 0 deletions gradle-conventions/src/main/kotlin/backintime-lint.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import org.jlleitschuh.gradle.ktlint.KtlintExtension
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
import util.libs

with(pluginManager) {
apply("org.jlleitschuh.gradle.ktlint")
}

configure<KtlintExtension> {
version.set(libs.findVersion("ktlint").get().requiredVersion)
ignoreFailures.set(true)
reporters {
reporter(ReporterType.CHECKSTYLE)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost

open class BackInTimePublicationExtension {
var artifactId: String = ""
}

extensions.create<BackInTimePublicationExtension>("backintimePublication")

with(pluginManager) {
apply("com.vanniktech.maven.publish")
}

afterEvaluate {
val extension = extensions.getByType(BackInTimePublicationExtension::class.java)
val artifactId = extension.artifactId
if (artifactId.isBlank()) error("Artifact ID must be specified.")

configure<MavenPublishBaseExtension> {
coordinates(artifactId = artifactId)

pom {
name.set("back-in-time")
description.set("Kondition ensure that your Kotlin code runs under some conditions are met. It inserts code to verify conditions for value parameters or variables at compile time.")
inceptionYear.set("2024")
url.set("https://github.com/kitakkun/back-in-time-plugin")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("https://github.com/kitakkun/back-in-time-plugin/blob/master/LICENSE")
distribution.set("repo")
}
developers {
developer {
id.set("kitakkun")
name.set("kitakkun")
url.set("https://github.com/kitakkun")
}
}
scm {
url.set("https://github.com/kitakkun/back-in-time-plugin")
connection.set("scm:git:git://github.com/kitakkun/back-in-time-plugin.git")
developerConnection.set("scm:git:ssh://[email protected]/kitakkun/back-in-time-plugin.git")
}
}
}

publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
signAllPublications()

// avoid failure when executing publishToMavenLocal
tasks.withType(Sign::class).configureEach {
onlyIf {
!gradle.startParameter.taskNames.contains("publishToMavenLocal")
}
}
}
}
25 changes: 8 additions & 17 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
rootProject.name = "backintime"

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

pluginManagement {
includeBuild("build-logic")
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
google()
}
includeBuild("gradle-conventions-settings")
includeBuild("gradle-conventions")
}

dependencyResolutionManagement {
repositories {
mavenLocal()
mavenCentral()
google()
}
plugins {
id("settings-conventions")
}

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

rootProject.name = "backintime"

include(
":plugin-common",
":gradle-plugin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ maven-publish = { module = "com.vanniktech:gradle-maven-publish-plugin", version

[plugins]
# convention
backintimeLint = { id = "backintime.lint", version = "unspecified" }
backintimePublication = { id = "backintime.publication", version = "unspecified" }
backintimeLint = { id = "backintime-lint", version = "unspecified" }
backintimePublication = { id = "backintime-publication", version = "unspecified" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint-gradle" }

kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
Expand Down

0 comments on commit 30e0d35

Please sign in to comment.