Upgrade the used JDK in the project to v21 (#3582)

* Upgrade the used JDK in the project to v21

* Use it for CI too

* Centralise java language version

* Fix deprecations, tests and lint issues

* Fix coverage taking into account `@Preview` annotated code.

---------

Co-authored-by: Benoit Marty <benoit@matrix.org>
This commit is contained in:
Jorge Martin Espinosa 2024-10-03 11:38:03 +02:00 committed by GitHub
parent 9f7e4d5022
commit f8fa218146
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 84 additions and 62 deletions

View file

@ -30,11 +30,11 @@ jobs:
# Ensure we are building the branch and not the branch after being merged on develop
# https://github.com/actions/checkout/issues/881
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }}
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
with:

View file

@ -38,11 +38,11 @@ jobs:
ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }}
- name: Clone submodules
run: git submodule update --init --recursive
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
with:

View file

@ -13,11 +13,11 @@ jobs:
steps:
- name: ⏬ Checkout with LFS
uses: nschloe/action-cached-lfs-checkout@v1.2.2
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
with:

View file

@ -13,11 +13,11 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
name: Use JDK 17
name: Use JDK 21
if: (github.event_name == 'pull_request' && github.event.pull_request.fork == null) || github.event_name == 'workflow_dispatch'
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Update Gradle Wrapper
uses: gradle-update/update-gradle-wrapper-action@v2
with:

View file

@ -33,11 +33,11 @@ jobs:
# https://github.com/actions/checkout/issues/881
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }}
- uses: actions/setup-java@v4
name: Use JDK 17
name: Use JDK 21
if: (github.event_name == 'pull_request' && github.event.pull_request.fork == null) || github.event_name == 'workflow_dispatch'
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
with:

View file

@ -17,11 +17,11 @@ jobs:
if: ${{ github.repository == 'element-hq/element-x-android' }}
steps:
- uses: actions/checkout@v4
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Build and upload Nightly application
run: |
./gradlew assembleGplayNightly appDistributionUploadGplayNightly $CI_GRADLE_ARG_PROPERTIES

View file

@ -20,11 +20,11 @@ jobs:
- name: ⏬ Checkout with LFS
uses: nschloe/action-cached-lfs-checkout@v1.2.2
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
@ -61,11 +61,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
with:

View file

@ -23,11 +23,11 @@ jobs:
ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }}
- name: Clone submodules
run: git submodule update --init --recursive
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Build and upload Nightly application
run: |
./gradlew assembleGplayNightly appDistributionUploadGplayNightly $CI_GRADLE_ARG_PROPERTIES

View file

@ -46,11 +46,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
with:
@ -84,11 +84,11 @@ jobs:
- name: Clone submodules
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'element-hq/element-x-android' }}
run: git submodule update --init --recursive
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
with:
@ -124,11 +124,11 @@ jobs:
- name: Clone submodules
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'element-hq/element-x-android' }}
run: git submodule update --init --recursive
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
with:
@ -168,11 +168,11 @@ jobs:
- name: Clone submodules
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'element-hq/element-x-android' }}
run: git submodule update --init --recursive
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
with:
@ -208,11 +208,11 @@ jobs:
- name: Clone submodules
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'element-hq/element-x-android' }}
run: git submodule update --init --recursive
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
with:
@ -248,11 +248,11 @@ jobs:
- name: Clone submodules
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'element-hq/element-x-android' }}
run: git submodule update --init --recursive
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
with:

View file

@ -32,11 +32,11 @@ jobs:
uses: nschloe/action-cached-lfs-checkout@v1.2.2
with:
persist-credentials: false
- name: ☕️ Use JDK 17
- name: ☕️ Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
# Add gradle cache, this should speed up the process
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4

View file

@ -19,11 +19,11 @@ jobs:
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
- name: Create app bundle
@ -55,11 +55,11 @@ jobs:
ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }}
- name: Clone submodules
run: git submodule update --init --recursive
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
- name: Create Enterprise app bundle
@ -83,11 +83,11 @@ jobs:
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
- name: Create APKs

View file

@ -27,11 +27,11 @@ jobs:
# Ensure we are building the branch and not the branch after being merged on develop
# https://github.com/actions/checkout/issues/881
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }}
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
with:

View file

@ -12,11 +12,11 @@ jobs:
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'element-hq/element-x-android' }}
steps:
- uses: actions/checkout@v4
- name: Use JDK 17
- name: Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
with:

View file

@ -46,11 +46,11 @@ jobs:
- name: Clone submodules
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'element-hq/element-x-android' }}
run: git submodule update --init --recursive
- name: ☕️ Use JDK 17
- name: ☕️ Use JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
- name: Configure gradle
uses: gradle/actions/setup-gradle@v4
with:

View file

@ -161,9 +161,6 @@ android {
}
}
}
kotlinOptions {
jvmTarget = "17"
}
buildFeatures {
buildConfig = true

View file

@ -11,8 +11,14 @@ plugins {
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = Versions.javaVersion
targetCompatibility = Versions.javaVersion
}
kotlin {
jvmToolchain {
languageVersion = Versions.javaLanguageVersion
}
}
dependencies {

View file

@ -7,11 +7,11 @@
package io.element.android.libraries.core.uri
import java.net.URL
import java.net.URI
fun String.isValidUrl(): Boolean {
return try {
URL(this)
URI(this).toURL()
true
} catch (t: Throwable) {
false

View file

@ -36,7 +36,7 @@ class DefaultLastMessageTimestampFormatterTest {
val now = "1980-04-06T18:35:24.00Z"
val dat = "1980-04-06T18:35:24.00Z"
val formatter = createFormatter(now)
assertThat(formatter.format(Instant.parse(dat).toEpochMilliseconds())).isEqualTo("6:35 PM")
assertThat(formatter.format(Instant.parse(dat).toEpochMilliseconds())).isEqualTo("6:35PM")
}
@Test
@ -44,7 +44,7 @@ class DefaultLastMessageTimestampFormatterTest {
val now = "1980-04-06T18:35:24.00Z"
val dat = "1980-04-06T18:35:23.00Z"
val formatter = createFormatter(now)
assertThat(formatter.format(Instant.parse(dat).toEpochMilliseconds())).isEqualTo("6:35 PM")
assertThat(formatter.format(Instant.parse(dat).toEpochMilliseconds())).isEqualTo("6:35PM")
}
@Test
@ -52,7 +52,7 @@ class DefaultLastMessageTimestampFormatterTest {
val now = "1980-04-06T18:35:24.00Z"
val dat = "1980-04-06T18:34:24.00Z"
val formatter = createFormatter(now)
assertThat(formatter.format(Instant.parse(dat).toEpochMilliseconds())).isEqualTo("6:34 PM")
assertThat(formatter.format(Instant.parse(dat).toEpochMilliseconds())).isEqualTo("6:34PM")
}
@Test
@ -60,7 +60,7 @@ class DefaultLastMessageTimestampFormatterTest {
val now = "1980-04-06T18:35:24.00Z"
val dat = "1980-04-06T17:35:24.00Z"
val formatter = createFormatter(now)
assertThat(formatter.format(Instant.parse(dat).toEpochMilliseconds())).isEqualTo("5:35 PM")
assertThat(formatter.format(Instant.parse(dat).toEpochMilliseconds())).isEqualTo("5:35PM")
}
@Test

View file

@ -54,8 +54,11 @@ object Versions {
val versionName = "$versionMajor.$versionMinor.$versionPatch"
const val compileSdk = 34
const val targetSdk = 34
// When updating the `minSdk`, make sure to update the value of `minSdkVersion` in the file `tools/release/release.sh`
val minSdk = if (isEnterpriseBuild) 26 else 24
val javaCompileVersion = JavaVersion.VERSION_17
val javaLanguageVersion: JavaLanguageVersion = JavaLanguageVersion.of(11)
private const val JAVA_VERSION = 21
val javaVersion: JavaVersion = JavaVersion.toVersion(JAVA_VERSION)
val javaLanguageVersion: JavaLanguageVersion = JavaLanguageVersion.of(JAVA_VERSION)
}

View file

@ -11,7 +11,6 @@ import Versions
import com.android.build.api.dsl.CommonExtension
import isEnterpriseBuild
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import java.io.File
@ -28,8 +27,8 @@ fun CommonExtension<*, *, *, *, *, *>.androidConfig(project: Project) {
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = Versions.javaVersion
targetCompatibility = Versions.javaVersion
}
testOptions {

View file

@ -104,8 +104,7 @@ fun Project.setupKover() {
annotatedBy(
"androidx.compose.ui.tooling.preview.Preview",
"io.element.android.libraries.architecture.coverage.ExcludeFromCoverage",
"io.element.android.libraries.designsystem.preview.PreviewsDayNight",
"io.element.android.libraries.designsystem.preview.PreviewWithLargeHeight",
"io.element.android.libraries.designsystem.preview.*",
)
}
}

View file

@ -29,6 +29,12 @@ android {
}
}
kotlin {
jvmToolchain {
languageVersion = Versions.javaLanguageVersion
}
}
dependencies {
commonDependencies(libs)
composeDependencies(libs)

View file

@ -29,6 +29,12 @@ android {
}
}
kotlin {
jvmToolchain {
languageVersion = Versions.javaLanguageVersion
}
}
dependencies {
commonDependencies(libs)
composeDependencies(libs)

View file

@ -26,6 +26,12 @@ android {
}
}
kotlin {
jvmToolchain {
languageVersion = Versions.javaLanguageVersion
}
}
dependencies {
commonDependencies(libs)
coreLibraryDesugaring(libs.android.desugar)