Skip to content

Commit

Permalink
Simplify JVM toolchain setup (#556)
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 authored Jun 3, 2024
1 parent 1c36393 commit 13d5b71
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 39 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ out/
.gradle/
build/

# Kotlin files
.kotlin/

# Local configuration file (sdk path, etc)
local.properties

Expand All @@ -38,6 +41,10 @@ captures/

# IntelliJ
*.iml
.idea/appInsightsSettings.xml
.idea/deploymentTargetSelector.xml
.idea/other.xml
.idea/studiobot.xml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
Expand Down
13 changes: 2 additions & 11 deletions build-logic/plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,14 @@
* License information is available from the LICENSE file.
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
}

group = "ch.srgssr.pillarbox.gradle"

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.majorVersion
}
kotlin {
jvmToolchain(17)
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@
*/
package ch.srgssr.pillarbox.gradle.internal

import org.gradle.api.JavaVersion
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

internal object AppConfig {
// When changing this value, don't forget to also update the Detekt config in the root `build.gradle.kts` file
private val javaVersionName = "17"

internal const val minSdk = 21
internal const val targetSdk = 34
internal const val compileSdk = 34

internal val javaVersion = JavaVersion.valueOf("VERSION_$javaVersionName")
internal val jvmTarget = JvmTarget.fromTarget(javaVersionName)
// When changing this value, don't forget to also update the Detekt config in the root `build.gradle.kts` file
internal val javaVersion = 17
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
package ch.srgssr.pillarbox.gradle.internal

import com.android.build.api.dsl.CommonExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension

internal val Project.libs: VersionCatalog
get() = extensions.getByType<VersionCatalogsExtension>().named("libs")

internal fun Project.configureAndroidModule(extension: CommonExtension<*, *, *, *, *, *>) = with(extension) {
namespace = "ch.srgssr.pillarbox." + name.removePrefix("pillarbox-").replace('-', '.')
Expand All @@ -21,8 +25,6 @@ internal fun Project.configureAndroidModule(extension: CommonExtension<*, *, *,
}

compileOptions {
sourceCompatibility = AppConfig.javaVersion
targetCompatibility = AppConfig.javaVersion
isCoreLibraryDesugaringEnabled = true
}

Expand All @@ -32,15 +34,15 @@ internal fun Project.configureAndroidModule(extension: CommonExtension<*, *, *,
}

dependencies {
// coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
add("coreLibraryDesugaring", "com.android.tools:desugar_jdk_libs:2.0.4")
// coreLibraryDesugaring(libs.findLibrary("android-desugar-jdk-libs").get())
add("coreLibraryDesugaring", libs.findLibrary("android-desugar-jdk-libs").get())
}
}

internal fun Project.configureKotlinModule() {
tasks.withType<KotlinCompile>().configureEach {
extensions.configure<KotlinAndroidProjectExtension> {
compilerOptions {
jvmTarget.set(AppConfig.jvmTarget)
jvmToolchain(AppConfig.javaVersion)
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ allprojects {
}
}

// Configure the `wrapper` task, so it can be easily be updated by simply running `./gradlew wrapper`.
tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
gradleVersion = "latest"
}

tasks.register<Delete>("clean") {
delete(rootProject.layout.buildDirectory)
}
Expand Down
11 changes: 2 additions & 9 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,8 @@ The latest stable version is [![Last release](https://img.shields.io/github/v/re
If not already enabled, you also need to turn on Java 17 support in every `build.gradle`/`build.gradle.kts` files using Pillarbox. To do so, add/update the following to/in the `android` section:

```kotlin
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = "17"
kotlin {
jvmToolchain(17)
}
```

Expand All @@ -125,8 +120,6 @@ A change in AndroidX Media3 1.3.0 requires applications to use library desugarin

```kotlin
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
isCoreLibraryDesugaringEnabled = true
}

Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[versions]
accompanist = "0.34.0"
android-desugar-jdk-libs = "2.0.4"
android-gradle-plugin = "8.4.1"
androidx-activity = "1.9.0"
androidx-annotation = "1.8.0"
Expand Down Expand Up @@ -41,6 +42,7 @@ turbine = "1.1.0"

[libraries]
accompanist-navigation-material = { module = "com.google.accompanist:accompanist-navigation-material", version.ref = "accompanist" }
android-desugar-jdk-libs = { module = "com.android.tools:desugar_jdk_libs", version.ref = "android-desugar-jdk-libs" }
android-gradle-api = { module = "com.android.tools.build:gradle-api", version.ref = "android-gradle-plugin" }
androidx-activity = { module = "androidx.activity:activity", version.ref = "androidx-activity" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" }
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down

0 comments on commit 13d5b71

Please sign in to comment.