build: allow to change java toolchain for build and tests

This commit is contained in:
Skylot 2024-10-15 21:34:03 +01:00
parent 958ab245ae
commit 548821c4df
No known key found for this signature in database
GPG Key ID: 47A4975761262B6A
6 changed files with 53 additions and 5 deletions

View File

@ -16,7 +16,7 @@ jobs:
uses: actions/setup-java@v4 uses: actions/setup-java@v4
with: with:
distribution: temurin distribution: temurin
java-version: 11 java-version: 21
- name: Set jadx version - name: Set jadx version
run: | run: |
@ -29,6 +29,8 @@ jobs:
- name: Build - name: Build
run: ./gradlew dist distWin run: ./gradlew dist distWin
env:
JADX_BUILD_JAVA_VERSION: 11
- name: Save bundle artifact - name: Save bundle artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4

View File

@ -20,10 +20,13 @@ jobs:
uses: actions/setup-java@v4 uses: actions/setup-java@v4
with: with:
distribution: temurin distribution: temurin
java-version: 11 java-version: 21
- name: Setup Gradle - name: Setup Gradle
uses: gradle/actions/setup-gradle@v4 uses: gradle/actions/setup-gradle@v4
- name: Build - name: Build
run: ./gradlew build dist distWin run: ./gradlew build dist distWin
env:
JADX_BUILD_JAVA_VERSION: 11

View File

@ -15,6 +15,18 @@ val jadxVersion by extra { System.getenv("JADX_VERSION") ?: "dev" }
println("jadx version: $jadxVersion") println("jadx version: $jadxVersion")
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 { allprojects {
apply(plugin = "java") apply(plugin = "java")
apply(plugin = "checkstyle") apply(plugin = "checkstyle")

View File

@ -8,6 +8,7 @@ plugins {
} }
val jadxVersion: String by rootProject.extra val jadxVersion: String by rootProject.extra
val jadxBuildJavaVersion: Int? by rootProject.extra
group = "io.github.skylot" group = "io.github.skylot"
version = jadxVersion version = jadxVersion
@ -32,6 +33,11 @@ repositories {
} }
java { java {
jadxBuildJavaVersion?.let { buildJavaVer ->
toolchain {
languageVersion = JavaLanguageVersion.of(buildJavaVer)
}
}
sourceCompatibility = JavaVersion.VERSION_11 sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11
} }

View File

@ -24,10 +24,31 @@ dependencies {
testImplementation("tools.profiler:async-profiler:3.0") testImplementation("tools.profiler:async-profiler:3.0")
} }
tasks.test { val jadxTestJavaVersion = getTestJavaVersion()
exclude("**/tmp/*")
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>("test") {
jadxTestJavaVersion?.let { testJavaVer ->
javaLauncher =
javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(testJavaVer)
}
}
// disable cache to allow test's rerun, // disable cache to allow test's rerun,
// because most tests are integration and depends on plugins and environment // because most tests are integration and depends on plugins and environment
outputs.cacheIf { false } outputs.cacheIf { false }
// exclude temp tests
exclude("**/tmp/*")
} }

View File

@ -1,9 +1,13 @@
rootProject.name = "jadx" plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version ("0.8.0")
}
if (!JavaVersion.current().isJava11Compatible) { if (!JavaVersion.current().isJava11Compatible) {
throw GradleException("Jadx requires at least Java 11 for build (current version is '${JavaVersion.current()}')") throw GradleException("Jadx requires at least Java 11 for build (current version is '${JavaVersion.current()}')")
} }
rootProject.name = "jadx"
include("jadx-core") include("jadx-core")
include("jadx-cli") include("jadx-cli")
include("jadx-gui") include("jadx-gui")