Skip to content

Commit

Permalink
Fixed setting jvm target version if toolchain is not set
Browse files Browse the repository at this point in the history
#KT-48226  Fixed
  • Loading branch information
ausatiy authored and Space committed Aug 22, 2021
1 parent 7296d9a commit ec793b4
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ internal abstract class DefaultKotlinJavaToolchain @Inject constructor(
.property(Jvm.current())
.chainedFinalizeValueOnRead()

@get:Internal
internal var providedJvmExplicitlySet = false

@get:Internal
internal val providedJvm: Property<Jvm> = objects
.propertyWithConvention(currentJvm)
Expand Down Expand Up @@ -115,6 +118,7 @@ internal abstract class DefaultKotlinJavaToolchain @Inject constructor(
providedJvm,
currentGradleVersion,
objects,
{ providedJvmExplicitlySet = true },
kotlinCompileTaskProvider
)

Expand Down Expand Up @@ -146,7 +150,7 @@ internal abstract class DefaultKotlinJavaToolchain @Inject constructor(
"\"updateJvmTarget()\" method should be called only on task execution!"
}

if (providedJvm.isPresent) {
if (providedJvmExplicitlySet) {
val jdkVersion = javaVersion.get()

// parentKotlinOptionsImpl is set from 'kotlin-android' plugin
Expand Down Expand Up @@ -195,6 +199,7 @@ internal abstract class DefaultKotlinJavaToolchain @Inject constructor(
private val providedJvm: Property<Jvm>,
private val currentGradleVersion: GradleVersion,
private val objects: ObjectFactory,
private val updateProvidedJdkCallback: () -> Unit,
kotlinCompileTaskProvider: () -> KotlinCompile?
) : JvmTargetUpdater(kotlinCompileTaskProvider),
KotlinJavaToolchain.JdkSetter {
Expand All @@ -210,6 +215,7 @@ internal abstract class DefaultKotlinJavaToolchain @Inject constructor(
"Supplied jdkHomeLocation does not exists. You supplied: $jdkHomeLocation"
}

updateProvidedJdkCallback.invoke()
providedJvm.set(
objects.providerWithLazyConvention {
updateJvmTarget(jdkVersion)
Expand All @@ -234,6 +240,7 @@ internal abstract class DefaultKotlinJavaToolchain @Inject constructor(
override fun use(
javaLauncher: Provider<JavaLauncher>
) {
providedJvmExplicitlySet = true
providedJvm.set(
javaLauncher.map {
val metadata = javaLauncher.get().metadata
Expand Down

0 comments on commit ec793b4

Please sign in to comment.