Skip to content

Commit

Permalink
cortinico#317 remove usage of internal / deprecated method calls in p…
Browse files Browse the repository at this point in the history
…reparatio for gradle 8.9 (cortinico#319)
  • Loading branch information
simonhauck authored Jul 12, 2024
1 parent 75c91b6 commit 7087bc0
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 98 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Please add your entries according to this format.

## Unreleased

- Update formatting of `build.gradle.kts` with ktfmt 0.51
- Replace deprecated methods in `build.gradle.kts` files
- Prepare for Gradle 8.9

## Version 0.19.0 _(2024-07-03)_

- Remove dropboxStyle since it is no longer supported by ktfmt. Use kotlinLangStyle() instead
Expand Down Expand Up @@ -113,7 +117,8 @@ Please add your entries according to this format.

- `--include-only` now works with paths that are file-separator independent.
- Added support for Gradle 7.0+
- Added task ordering between `ktfmt*` tasks and `compileKotlin` tasks. This fix the correctness warning introduced with Gradle 7.0
- Added task ordering between `ktfmt*` tasks and `compileKotlin` tasks. This fix the correctness warning introduced with
Gradle 7.0

### Dependencies Update

Expand All @@ -139,7 +144,8 @@ Please add your entries according to this format.

### New features

- Added the `kotlinLangStyle()` function to the `ktfmt{}` extension. This will allow you to apply a format that attempts to reflect the [official kotlin convetions](https://kotlinlang.org/docs/coding-conventions.html).
- Added the `kotlinLangStyle()` function to the `ktfmt{}` extension. This will allow you to apply a format that attempts
to reflect the [official kotlin convetions](https://kotlinlang.org/docs/coding-conventions.html).

### Dependencies Update

Expand Down
18 changes: 4 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,16 @@ plugins {
}

subprojects {
apply {
plugin(rootProject.libs.plugins.detekt.get().pluginId)
}
apply { plugin(rootProject.libs.plugins.detekt.get().pluginId) }

detekt {
config.setFrom(rootProject.files("config/detekt/detekt.yml"))
}
detekt { config.setFrom(rootProject.files("config/detekt/detekt.yml")) }
}

tasks.withType<DependencyUpdatesTask> {
rejectVersionIf {
isNonStable(candidate.version)
}
}
tasks.withType<DependencyUpdatesTask> { rejectVersionIf { isNonStable(candidate.version) } }

fun isNonStable(version: String) = "^[0-9,.v-]+(-r)?$".toRegex().matches(version).not()

tasks.register("clean", Delete::class.java) {
delete(rootProject.buildDir)
}
tasks.register<Delete>("clean") { delete(layout.buildDirectory) }

tasks.register("reformatAll") {
description = "Reformat all the Kotlin Code"
Expand Down
8 changes: 2 additions & 6 deletions example-kmp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@ kotlin {
androidTarget()
}

ktfmt {
kotlinLangStyle()
}
ktfmt { kotlinLangStyle() }

android {
namespace = "com.ncorti.example.ktfmt"
compileSdk = 33
}

tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<Test> { useJUnitPlatform() }

dependencies {
testImplementation(platform(libs.junit.bom))
Expand Down
20 changes: 4 additions & 16 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ plugins {
id("app.cash.sqldelight") version "2.0.2"
}

ktfmt {
kotlinLangStyle()
}
ktfmt { kotlinLangStyle() }

kotlin {
jvmToolchain(17)
}
kotlin { jvmToolchain(17) }

dependencies {
testImplementation(platform(libs.junit.bom))
Expand All @@ -21,14 +17,6 @@ dependencies {
ksp("com.squareup.moshi:moshi-kotlin-codegen:1.15.1")
}

tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<Test> { useJUnitPlatform() }

sqldelight {
databases {
create("Database") {
packageName.set("com.example")
}
}
}
sqldelight { databases { create("Database") { packageName.set("com.example") } } }
18 changes: 4 additions & 14 deletions plugin-build/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,13 @@ allprojects {
plugin(rootProject.libs.plugins.ktfmt.get().pluginId)
}

ktfmt {
kotlinLangStyle()
}
ktfmt { kotlinLangStyle() }

detekt {
config.setFrom(rootProject.files("../config/detekt/detekt.yml"))
}
detekt { config.setFrom(rootProject.files("../config/detekt/detekt.yml")) }
}

tasks.withType<DependencyUpdatesTask> {
rejectVersionIf {
isNonStable(candidate.version)
}
}
tasks.withType<DependencyUpdatesTask> { rejectVersionIf { isNonStable(candidate.version) } }

fun isNonStable(version: String) = "^[0-9,.v-]+(-r)?$".toRegex().matches(version).not()

tasks.register("clean", Delete::class.java) {
delete(rootProject.buildDir)
}
tasks.register<Delete>("clean") { delete(layout.buildDirectory) }
62 changes: 22 additions & 40 deletions plugin-build/plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import org.gradle.api.internal.classpath.ModuleRegistry
import org.gradle.configurationcache.extensions.serviceOf
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion

plugins {
kotlin("jvm")
Expand All @@ -14,18 +13,21 @@ java {
targetCompatibility = JavaVersion.VERSION_11
}

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
kotlin {
compilerOptions {
apiVersion.set(KotlinVersion.fromVersion("1.4"))
languageVersion.set(KotlinVersion.fromVersion("1.4"))
jvmTarget = JvmTarget.JVM_11
}
}

/**
* We create a configuration that we can resolve by extending [compileOnly].
* Here we inject the dependencies into TestKit plugin
* classpath via [PluginUnderTestMetadata] to make them available for testing.
* We create a configuration that we can resolve by extending [compileOnly]. Here we inject the
* dependencies into TestKit plugin classpath via [PluginUnderTestMetadata] to make them available
* for testing.
*/
val integrationTestRuntime: Configuration by configurations.creating

integrationTestRuntime.apply {
extendsFrom(configurations.getByName("compileOnly"))
attributes {
Expand All @@ -38,15 +40,6 @@ tasks.withType<PluginUnderTestMetadata>().configureEach {
pluginClasspath.from(integrationTestRuntime)
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + "-opt-in=kotlin.RequiresOptIn"
jvmTarget = JavaVersion.VERSION_11.toString()
apiVersion = "1.4"
languageVersion = "1.4"
}
}

dependencies {
compileOnly(libs.ktfmt)
implementation(libs.diffUtils)
Expand All @@ -63,15 +56,9 @@ dependencies {
testImplementation(libs.truth)

testImplementation(libs.ktfmt)

testRuntimeOnly(
files(
serviceOf<ModuleRegistry>().getModule("gradle-tooling-api-builders")
.classpath.asFiles.first()
)
)
}

@Suppress("UnstableApiUsage")
gradlePlugin {
plugins {
create(property("ID").toString()) {
Expand All @@ -80,12 +67,12 @@ gradlePlugin {
version = property("VERSION").toString()
displayName = property("DISPLAY_NAME").toString()
description = property("DESCRIPTION").toString()
tags.set(listOf("ktfmt", "kotlin", "formatter", "reformat", "style", "code", "linter"))
tags = listOf("ktfmt", "kotlin", "formatter", "reformat", "style", "code", "linter")
}
}

website.set(property("WEBSITE").toString())
vcsUrl.set(property("VCS_URL").toString())
website = property("WEBSITE").toString()
vcsUrl = property("VCS_URL").toString()
}

signing {
Expand All @@ -96,20 +83,15 @@ signing {

tasks.withType<Sign>().configureEach { onlyIf { project.properties["skip-signing"] != "true" } }

tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<Test> { useJUnitPlatform() }

val persistKtmftVersion by tasks.registering {
inputs.property("ktfmtVersion", libs.ktfmt)
outputs.files(layout.buildDirectory.file("ktfmt-version.txt"))
doLast {
outputs.files.singleFile.writeText(inputs.properties["ktfmtVersion"].toString())
val persistKtfmtVersion by
tasks.registering {
inputs.property("ktfmtVersion", libs.ktfmt)
outputs.files(layout.buildDirectory.file("ktfmt-version.txt"))
doLast { outputs.files.singleFile.writeText(inputs.properties["ktfmtVersion"].toString()) }
}
}

tasks.named<ProcessResources>("processResources") {
from(persistKtmftVersion) {
into("com/ncorti/ktfmt/gradle")
}
from(persistKtfmtVersion) { into("com/ncorti/ktfmt/gradle") }
}
6 changes: 1 addition & 5 deletions plugin-build/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ dependencyResolutionManagement {
mavenCentral()
}

versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
versionCatalogs { create("libs") { from(files("../gradle/libs.versions.toml")) } }
}

rootProject.name = ("com.ncorti.ktfmt.gradle")
Expand Down
5 changes: 4 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ include(
":example",
":example-kmp",
)
includeBuild("plugin-build")

includeBuild(
"plugin-build",
)

0 comments on commit 7087bc0

Please sign in to comment.