Skip to content

Commit

Permalink
Target Java 1.8 for Circuit published libraries (from Java 11) (#1378)
Browse files Browse the repository at this point in the history
Our problem is we want to use Circuit in a SDK potentially used by AGP
4.0 / Java 8 consumers (Unity). Since Circuit target Java 11 we can't
build the consumer app. Since current androidx libraries are built for
Java 8 it makes sense to downgrade from Java 11 to Java 8 (until
androidx team decide to bump to Java 11).

In this change only published libraries are impacted. Published library
mean a `POM_ARTIFACT_ID` property exists.

The change was tested successfully using a Unity 2020 project with the
Circuit counter sample added to our SDK.
  • Loading branch information
eboudrant authored Apr 30, 2024
1 parent cae5366 commit 8ebb890
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
19 changes: 15 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,12 @@ fun Project.configureComposeBom(dependencyHandler: DependencyHandler) {
}

val jvmTargetVersion = libs.versions.jvmTarget
val publishedJvmTargetVersion = libs.versions.publishedJvmTarget

subprojects {
val isPublished = project.hasProperty("POM_ARTIFACT_ID")
val jvmTargetProject = if (isPublished) publishedJvmTargetVersion else jvmTargetVersion

pluginManager.withPlugin("java") {
configure<JavaPluginExtension> {
toolchain {
Expand All @@ -151,7 +155,9 @@ subprojects {
}

tasks.withType<JavaCompile>().configureEach {
options.release.set(jvmTargetVersion.map(String::toInt))
options.release.set(
jvmTargetProject.map(JavaVersion::toVersion).map { it.majorVersion.toInt() }
)
}

// This is the default base plugin applied on all projects, so safe to add this hook here
Expand All @@ -167,7 +173,12 @@ subprojects {
compilerOptions {
allWarningsAsErrors.set(true)
if (this is KotlinJvmCompilerOptions) {
jvmTarget.set(jvmTargetVersion.map(JvmTarget::fromTarget))
jvmTarget.set(
jvmTargetProject
.map(JavaVersion::toVersion)
.map { it.toString() }
.map(JvmTarget::fromTarget)
)
// Stub gen copies args from the parent compilation
if (this@configureEach !is KaptGenerateStubsTask) {
freeCompilerArgs.addAll(
Expand Down Expand Up @@ -340,8 +351,8 @@ subprojects {
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = jvmTargetProject.map(JavaVersion::toVersion).get()
targetCompatibility = jvmTargetProject.map(JavaVersion::toVersion).get()
}

lint {
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dokka = "1.9.20"
eithernet = "1.8.1"
jdk = "21"
jvmTarget = "11"
publishedJvmTarget = "1.8"
kct = "0.4.1"
kotlin = "1.9.23"
kotlinpoet = "1.16.0"
Expand Down

0 comments on commit 8ebb890

Please sign in to comment.