From 548821c4df16eba63be8df26bc1d3a9fceda5d35 Mon Sep 17 00:00:00 2001 From: Skylot <118523+skylot@users.noreply.github.com> Date: Tue, 15 Oct 2024 21:34:03 +0100 Subject: [PATCH] build: allow to change java toolchain for build and tests --- .github/workflows/build-artifacts.yml | 4 ++- .github/workflows/build-test.yml | 5 +++- build.gradle.kts | 12 +++++++++ buildSrc/src/main/kotlin/jadx-java.gradle.kts | 6 +++++ jadx-core/build.gradle.kts | 25 +++++++++++++++++-- settings.gradle.kts | 6 ++++- 6 files changed, 53 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-artifacts.yml b/.github/workflows/build-artifacts.yml index c84a60f5..f036fca6 100644 --- a/.github/workflows/build-artifacts.yml +++ b/.github/workflows/build-artifacts.yml @@ -16,7 +16,7 @@ jobs: uses: actions/setup-java@v4 with: distribution: temurin - java-version: 11 + java-version: 21 - name: Set jadx version run: | @@ -29,6 +29,8 @@ jobs: - name: Build run: ./gradlew dist distWin + env: + JADX_BUILD_JAVA_VERSION: 11 - name: Save bundle artifact uses: actions/upload-artifact@v4 diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index a67f9f17..91482402 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -20,10 +20,13 @@ jobs: uses: actions/setup-java@v4 with: distribution: temurin - java-version: 11 + java-version: 21 - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - name: Build run: ./gradlew build dist distWin + env: + JADX_BUILD_JAVA_VERSION: 11 + diff --git a/build.gradle.kts b/build.gradle.kts index e4cecb47..99ec0cb4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,6 +15,18 @@ val jadxVersion by extra { System.getenv("JADX_VERSION") ?: "dev" } println("jadx version: $jadxVersion") version = jadxVersion +val jadxBuildJavaVersion by extra { getBuildJavaVersion() } + +fun getBuildJavaVersion(): Int? { + val envVarName = "JADX_BUILD_JAVA_VERSION" + val buildJavaVer = System.getenv(envVarName)?.toInt() ?: return null + if (buildJavaVer < 11) { + throw GradleException("'$envVarName' can't be set to lower than 11") + } + println("Set Java toolchain for jadx build to version '$buildJavaVer'") + return buildJavaVer +} + allprojects { apply(plugin = "java") apply(plugin = "checkstyle") diff --git a/buildSrc/src/main/kotlin/jadx-java.gradle.kts b/buildSrc/src/main/kotlin/jadx-java.gradle.kts index 844befbd..fa234c45 100644 --- a/buildSrc/src/main/kotlin/jadx-java.gradle.kts +++ b/buildSrc/src/main/kotlin/jadx-java.gradle.kts @@ -8,6 +8,7 @@ plugins { } val jadxVersion: String by rootProject.extra +val jadxBuildJavaVersion: Int? by rootProject.extra group = "io.github.skylot" version = jadxVersion @@ -32,6 +33,11 @@ repositories { } java { + jadxBuildJavaVersion?.let { buildJavaVer -> + toolchain { + languageVersion = JavaLanguageVersion.of(buildJavaVer) + } + } sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 } diff --git a/jadx-core/build.gradle.kts b/jadx-core/build.gradle.kts index ccfd69a8..7fb87c57 100644 --- a/jadx-core/build.gradle.kts +++ b/jadx-core/build.gradle.kts @@ -24,10 +24,31 @@ dependencies { testImplementation("tools.profiler:async-profiler:3.0") } -tasks.test { - exclude("**/tmp/*") +val jadxTestJavaVersion = getTestJavaVersion() + +fun getTestJavaVersion(): Int? { + val envVarName = "JADX_TEST_JAVA_VERSION" + val testJavaVer = System.getenv(envVarName)?.toInt() ?: return null + val currentJavaVer = java.toolchain.languageVersion.get().asInt() + if (testJavaVer < currentJavaVer) { + throw GradleException("'$envVarName' can't be set to lower version than $currentJavaVer") + } + println("Set Java toolchain for core tests to version '$testJavaVer'") + return testJavaVer +} + +tasks.named("test") { + jadxTestJavaVersion?.let { testJavaVer -> + javaLauncher = + javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(testJavaVer) + } + } // disable cache to allow test's rerun, // because most tests are integration and depends on plugins and environment outputs.cacheIf { false } + + // exclude temp tests + exclude("**/tmp/*") } diff --git a/settings.gradle.kts b/settings.gradle.kts index 5cee7391..f6fc258a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,9 +1,13 @@ -rootProject.name = "jadx" +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version ("0.8.0") +} if (!JavaVersion.current().isJava11Compatible) { throw GradleException("Jadx requires at least Java 11 for build (current version is '${JavaVersion.current()}')") } +rootProject.name = "jadx" + include("jadx-core") include("jadx-cli") include("jadx-gui")