From 15990d56cc8b9105050c72fec8d685f58effe260 Mon Sep 17 00:00:00 2001 From: Alexey Illarionov Date: Mon, 22 Jan 2024 20:00:46 +0300 Subject: [PATCH] Update jvm target (#254) * Update JvmTarget to 17, refactor build scripts * Remove apply false plugins (this doesn't work in precompiled plugins) * remove targetCompatibility --- gradle/libs.versions.toml | 2 +- .../ru.pixnews.gradle.android.crashlytics.gradle.kts | 5 ++--- .../ru.pixnews.gradle.android.room-kapt.gradle.kts | 10 +++++----- .../ru.pixnews.gradle.android.room.gradle.kts | 12 ++++++------ ....pixnews.gradle.android.test-paparazzi.gradle.kts | 3 +-- .../ru/pixnews/gradle/android/AndroidCommon.kt | 7 +++---- .../project/base/project-plugin-base.gradle.kts | 3 +-- .../ru.pixnews.gradle.kotlin.library.gradle.kts | 5 ++--- .../ru.pixnews.gradle.lint.android-lint.gradle.kts | 4 ++-- gradle/plugin/project/project-plugins.gradle.kts | 2 +- .../testing/project-plugin-testing.gradle.kts | 2 +- .../gradle/testing/TestCommonConfiguration.kt | 2 +- 12 files changed, 26 insertions(+), 31 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d4722f95..dd784fd0 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,7 +9,7 @@ anvil = "2.4.9" bmversions = "0.50.0" detekt = "1.23.4" diktat = "1.2.5" -detekt-compose-rules = "0.3.8" +detekt-compose-rules = "0.3.10" dagger = "2.50" kotlin = "1.9.22" ksp = "1.9.22-1.0.17" diff --git a/gradle/plugin/project/android/convention/ru.pixnews.gradle.android.crashlytics.gradle.kts b/gradle/plugin/project/android/convention/ru.pixnews.gradle.android.crashlytics.gradle.kts index 6a881a3d..5ba45d78 100644 --- a/gradle/plugin/project/android/convention/ru.pixnews.gradle.android.crashlytics.gradle.kts +++ b/gradle/plugin/project/android/convention/ru.pixnews.gradle.android.crashlytics.gradle.kts @@ -11,7 +11,6 @@ import ru.pixnews.gradle.base.versionCatalog * Convention plugin that configures crashlytics */ plugins { - id("com.android.application") apply false id("ru.pixnews.gradle.base.build-parameters") id("com.google.firebase.crashlytics") } @@ -33,6 +32,6 @@ extensions.configure("android") { } dependencies { - implementation(versionCatalog.findLibrary("firebase.analytics").get()) - implementation(versionCatalog.findLibrary("firebase.crashlytics").get()) + add("implementation", versionCatalog.findLibrary("firebase.analytics").get()) + add("implementation", versionCatalog.findLibrary("firebase.crashlytics").get()) } diff --git a/gradle/plugin/project/android/convention/ru.pixnews.gradle.android.room-kapt.gradle.kts b/gradle/plugin/project/android/convention/ru.pixnews.gradle.android.room-kapt.gradle.kts index 2fc5ab8d..89f57cac 100644 --- a/gradle/plugin/project/android/convention/ru.pixnews.gradle.android.room-kapt.gradle.kts +++ b/gradle/plugin/project/android/convention/ru.pixnews.gradle.android.room-kapt.gradle.kts @@ -3,6 +3,7 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ +import androidx.room.gradle.RoomExtension import com.android.build.api.dsl.CommonExtension import ru.pixnews.gradle.base.versionCatalog @@ -12,13 +13,12 @@ import ru.pixnews.gradle.base.versionCatalog * For cases when [ru.pixnews.gradle.android.room] doesn't work */ plugins { - id("com.android.library") apply false id("androidx.room") id("ru.pixnews.gradle.base.build-parameters") kotlin("kapt") } -room { +extensions.configure { schemaDirectory("$projectDir/schemas/") } @@ -35,8 +35,8 @@ extensions.configure>("android") { } dependencies { - annotationProcessor(versionCatalog.findLibrary("androidx.room.compiler").get()) - api(versionCatalog.findLibrary("androidx.room").get()) + add("annotationProcessor", versionCatalog.findLibrary("androidx.room.compiler").get()) + add("api", versionCatalog.findLibrary("androidx.room").get()) add("kapt", versionCatalog.findLibrary("androidx.room.compiler").get()) - testImplementation(versionCatalog.findLibrary("androidx.room.testing").get()) + add("testImplementation", versionCatalog.findLibrary("androidx.room.testing").get()) } diff --git a/gradle/plugin/project/android/convention/ru.pixnews.gradle.android.room.gradle.kts b/gradle/plugin/project/android/convention/ru.pixnews.gradle.android.room.gradle.kts index 16fcc520..e494426d 100644 --- a/gradle/plugin/project/android/convention/ru.pixnews.gradle.android.room.gradle.kts +++ b/gradle/plugin/project/android/convention/ru.pixnews.gradle.android.room.gradle.kts @@ -3,6 +3,7 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ +import androidx.room.gradle.RoomExtension import com.android.build.api.dsl.CommonExtension import ru.pixnews.gradle.base.versionCatalog @@ -10,13 +11,12 @@ import ru.pixnews.gradle.base.versionCatalog * Convention plugin that configures Room */ plugins { - id("com.android.library") apply false id("androidx.room") id("com.google.devtools.ksp") id("ru.pixnews.gradle.base.build-parameters") } -room { +extensions.configure { schemaDirectory("$projectDir/schemas/") } @@ -34,9 +34,9 @@ extensions.configure>("android") { } dependencies { - annotationProcessor(versionCatalog.findLibrary("androidx.room.compiler").get()) - api(versionCatalog.findLibrary("androidx.room").get()) - ksp(versionCatalog.findLibrary("androidx.room.compiler").get()) + add("annotationProcessor", versionCatalog.findLibrary("androidx.room.compiler").get()) + add("api", versionCatalog.findLibrary("androidx.room").get()) + add("ksp", versionCatalog.findLibrary("androidx.room.compiler").get()) - testImplementation(versionCatalog.findLibrary("androidx.room.testing").get()) + add("testImplementation", versionCatalog.findLibrary("androidx.room.testing").get()) } diff --git a/gradle/plugin/project/android/convention/ru.pixnews.gradle.android.test-paparazzi.gradle.kts b/gradle/plugin/project/android/convention/ru.pixnews.gradle.android.test-paparazzi.gradle.kts index f324e1d1..be329aec 100644 --- a/gradle/plugin/project/android/convention/ru.pixnews.gradle.android.test-paparazzi.gradle.kts +++ b/gradle/plugin/project/android/convention/ru.pixnews.gradle.android.test-paparazzi.gradle.kts @@ -11,7 +11,6 @@ import ru.pixnews.gradle.base.versionCatalog * Convention plugin with paparazzi configuration */ plugins { - id("com.android.library") apply false id("app.cash.paparazzi") } @@ -29,7 +28,7 @@ plugins.withType { dependencies { "testImplementation"(versionCatalog.findLibrary("junit-jupiter-vintage-engine").get()) constraints { - testImplementation("com.google.guava:guava") { + add("testImplementation", "com.google.guava:guava") { attributes { attribute( TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, diff --git a/gradle/plugin/project/android/src/main/kotlin/ru/pixnews/gradle/android/AndroidCommon.kt b/gradle/plugin/project/android/src/main/kotlin/ru/pixnews/gradle/android/AndroidCommon.kt index 5ce629b3..3b455a3e 100644 --- a/gradle/plugin/project/android/src/main/kotlin/ru/pixnews/gradle/android/AndroidCommon.kt +++ b/gradle/plugin/project/android/src/main/kotlin/ru/pixnews/gradle/android/AndroidCommon.kt @@ -33,16 +33,15 @@ internal fun Project.configureCommonAndroid( } compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - // https://issuetracker.google.com/u/1/issues/266687543 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 isCoreLibraryDesugaringEnabled = true } tasks.withType>() .configureEach { compilerOptions { - jvmTarget.set(JvmTarget.JVM_11) + jvmTarget.set(JvmTarget.JVM_17) // There are some plugins incompatible with K2 compiler: // ComposeCompiler, R8 // languageVersion.set(KOTLIN_2_0) diff --git a/gradle/plugin/project/base/project-plugin-base.gradle.kts b/gradle/plugin/project/base/project-plugin-base.gradle.kts index b13fa73f..6a34fa7a 100644 --- a/gradle/plugin/project/base/project-plugin-base.gradle.kts +++ b/gradle/plugin/project/base/project-plugin-base.gradle.kts @@ -3,12 +3,11 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ plugins { - alias(libs.plugins.kotlin.jvm) + id("ru.pixnews.gradle.base.kotlindsl") } group = "ru.pixnews.gradle" dependencies { - implementation(gradleKotlinDsl()) implementation("ru.pixnews.gradle.base:gradle-build-parameters") } diff --git a/gradle/plugin/project/kotlin/convention/ru.pixnews.gradle.kotlin.library.gradle.kts b/gradle/plugin/project/kotlin/convention/ru.pixnews.gradle.kotlin.library.gradle.kts index 2db31d40..e2d1853a 100644 --- a/gradle/plugin/project/kotlin/convention/ru.pixnews.gradle.kotlin.library.gradle.kts +++ b/gradle/plugin/project/kotlin/convention/ru.pixnews.gradle.kotlin.library.gradle.kts @@ -44,14 +44,13 @@ plugins.withId("java-test-fixtures") { } java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 + sourceCompatibility = JavaVersion.VERSION_17 } tasks.withType>() .configureEach { compilerOptions { - jvmTarget.set(JvmTarget.JVM_11) + jvmTarget.set(JvmTarget.JVM_17) // D8: An error occurred when parsing kotlin metadata. // languageVersion.set(KOTLIN_2_0) freeCompilerArgs.addAll( diff --git a/gradle/plugin/project/lint/convention/ru.pixnews.gradle.lint.android-lint.gradle.kts b/gradle/plugin/project/lint/convention/ru.pixnews.gradle.lint.android-lint.gradle.kts index 72c48cf5..daa6abba 100644 --- a/gradle/plugin/project/lint/convention/ru.pixnews.gradle.lint.android-lint.gradle.kts +++ b/gradle/plugin/project/lint/convention/ru.pixnews.gradle.lint.android-lint.gradle.kts @@ -14,7 +14,7 @@ import ru.pixnews.gradle.lint.configureCommonAndroidLint * Convention plugin that configures Android Lint in projects with the Android Gradle plugin */ project.plugins.withType(AppPlugin::class.java) { - extensions.configure>("android") { + extensions.configure(CommonExtension::class.java) { lint { configureCommonAndroidLint() checkDependencies = true @@ -28,7 +28,7 @@ listOf( TestPlugin::class.java, ).forEach { agpLibraryPlugin -> plugins.withType(agpLibraryPlugin) { - extensions.configure>("android") { + extensions.configure(CommonExtension::class.java) { lint { configureCommonAndroidLint() } diff --git a/gradle/plugin/project/project-plugins.gradle.kts b/gradle/plugin/project/project-plugins.gradle.kts index 1e7971e8..34b178a7 100644 --- a/gradle/plugin/project/project-plugins.gradle.kts +++ b/gradle/plugin/project/project-plugins.gradle.kts @@ -3,5 +3,5 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ plugins { - alias(libs.plugins.kotlin.jvm) apply false + id("ru.pixnews.gradle.base.kotlindsl") apply false } diff --git a/gradle/plugin/project/testing/project-plugin-testing.gradle.kts b/gradle/plugin/project/testing/project-plugin-testing.gradle.kts index f3b36ebe..1db1705a 100644 --- a/gradle/plugin/project/testing/project-plugin-testing.gradle.kts +++ b/gradle/plugin/project/testing/project-plugin-testing.gradle.kts @@ -4,7 +4,7 @@ */ plugins { - alias(libs.plugins.kotlin.jvm) + id("ru.pixnews.gradle.base.kotlindsl") } group = "ru.pixnews.gradle.testing" diff --git a/gradle/plugin/project/testing/src/main/kotlin/ru/pixnews/gradle/testing/TestCommonConfiguration.kt b/gradle/plugin/project/testing/src/main/kotlin/ru/pixnews/gradle/testing/TestCommonConfiguration.kt index 3713a8bb..4b89e984 100644 --- a/gradle/plugin/project/testing/src/main/kotlin/ru/pixnews/gradle/testing/TestCommonConfiguration.kt +++ b/gradle/plugin/project/testing/src/main/kotlin/ru/pixnews/gradle/testing/TestCommonConfiguration.kt @@ -56,7 +56,7 @@ private fun Test.configureCommonJunit5TestOptions() { STANDARD_ERROR, ) } - it.events = logEvents + events = logEvents } }