[Gradle] Fix eager task realization due to attributes querying

Gradle 8.3+ starts triggering JVM eager tasks creating via eagerly
configured attributes that we copy over from the Gradle JVM plugin for
Kotlin compilation. The fix is to migrate to '.attributeProvider()' API
to configure the attribute.

^KT-60664 In Progress
This commit is contained in:
Yahor Berdnikau
2023-12-21 22:18:33 +01:00
committed by Space Team
parent 2da6946ac2
commit dbd77fc785
58 changed files with 563 additions and 222 deletions
@@ -52,8 +52,14 @@ fun KotlinMultiplatformExtension.androidTargetPrototype(): PrototypeAndroidTarge
In this example we hardcoded AGP version 7.4.0-beta02 as demo
*/
apiElements.configure { _, configuration ->
configuration.attributes.attribute(TARGET_JVM_ENVIRONMENT_ATTRIBUTE, project.objects.named(TargetJvmEnvironment.ANDROID))
configuration.attributes.attribute(AgpVersionAttr.ATTRIBUTE, project.objects.named("7.4.0-beta02")) /* For demo */
configuration.attributes.attributeProvider(
TARGET_JVM_ENVIRONMENT_ATTRIBUTE,
project.provider { project.objects.named(TargetJvmEnvironment.ANDROID) }
)
configuration.attributes.attributeProvider(
AgpVersionAttr.ATTRIBUTE,
project.provider { project.objects.named("7.4.0-beta02") } /* For demo */
)
}
/*
@@ -61,8 +67,14 @@ fun KotlinMultiplatformExtension.androidTargetPrototype(): PrototypeAndroidTarge
In this example we hardcoded AGP version 7.4.0-beta02 as demo
*/
runtimeElements.configure { _, configuration ->
configuration.attributes.attribute(TARGET_JVM_ENVIRONMENT_ATTRIBUTE, project.objects.named(TargetJvmEnvironment.ANDROID))
configuration.attributes.attribute(AgpVersionAttr.ATTRIBUTE, project.objects.named("7.4.0-beta02")) /* For demo */
configuration.attributes.attributeProvider(
TARGET_JVM_ENVIRONMENT_ATTRIBUTE,
project.provider { project.objects.named(TargetJvmEnvironment.ANDROID) }
)
configuration.attributes.attributeProvider(
AgpVersionAttr.ATTRIBUTE,
project.provider { project.objects.named("7.4.0-beta02") } /* For demo */
)
}
/*
@@ -70,8 +82,16 @@ fun KotlinMultiplatformExtension.androidTargetPrototype(): PrototypeAndroidTarge
In this example we hardcoded AGP version 7.4.0-beta02 as demo
*/
sourcesElements.configure { _, configuration ->
configuration.attributes.attribute(TARGET_JVM_ENVIRONMENT_ATTRIBUTE, project.objects.named(TargetJvmEnvironment.ANDROID))
configuration.attributes.attribute(AgpVersionAttr.ATTRIBUTE, project.objects.named("7.4.0-beta02")) /* For demo */
configuration.attributes.attributeProvider(
TARGET_JVM_ENVIRONMENT_ATTRIBUTE,
project.provider { project.objects.named(TargetJvmEnvironment.ANDROID) }
)
configuration.attributes.attributeProvider(
AgpVersionAttr.ATTRIBUTE,
project.provider {
project.objects.named("7.4.0-beta02") /* For demo */
}
)
}
/*
@@ -80,14 +100,30 @@ fun KotlinMultiplatformExtension.androidTargetPrototype(): PrototypeAndroidTarge
*/
apiElementsPublished.configure { _, configuration ->
/* TODO w/ Google: Find a way to deprecate this attribute */
configuration.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm)
configuration.attributes.attribute(TARGET_JVM_ENVIRONMENT_ATTRIBUTE, project.objects.named(TargetJvmEnvironment.ANDROID))
configuration.attributes.attributeProvider(
KotlinPlatformType.attribute,
project.provider { KotlinPlatformType.androidJvm }
)
configuration.attributes.attributeProvider(
TARGET_JVM_ENVIRONMENT_ATTRIBUTE,
project.provider {
project.objects.named(TargetJvmEnvironment.ANDROID)
}
)
}
runtimeElementsPublished.configure { _, configuration ->
/* TODO w/ Google: Find a way to deprecate this attribute */
configuration.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm)
configuration.attributes.attribute(TARGET_JVM_ENVIRONMENT_ATTRIBUTE, project.objects.named(TargetJvmEnvironment.ANDROID))
configuration.attributes.attributeProvider(
KotlinPlatformType.attribute,
project.provider { KotlinPlatformType.androidJvm }
)
configuration.attributes.attributeProvider(
TARGET_JVM_ENVIRONMENT_ATTRIBUTE,
project.provider {
project.objects.named(TargetJvmEnvironment.ANDROID)
}
)
}
configureIdeImport {
@@ -165,7 +201,10 @@ fun KotlinMultiplatformExtension.androidTargetPrototype(): PrototypeAndroidTarge
artifactType: CLASSES_JAR
*/
androidTarget.apiElementsConfiguration.outgoing.variants.create("classes").let { variant ->
variant.attributes.attribute(AndroidArtifacts.ARTIFACT_TYPE, AndroidArtifacts.ArtifactType.CLASSES_JAR.type)
variant.attributes.attributeProvider(
AndroidArtifacts.ARTIFACT_TYPE,
project.provider { AndroidArtifacts.ArtifactType.CLASSES_JAR.type }
)
variant.artifact(mainCompilation.output.classesDirs.singleFile) {
it.builtBy(mainCompilation.output.classesDirs)
}
@@ -178,7 +217,10 @@ fun KotlinMultiplatformExtension.androidTargetPrototype(): PrototypeAndroidTarge
artifactType: CLASSES_JAR
*/
androidTarget.runtimeElementsConfiguration.outgoing.variants.create("classes").let { variant ->
variant.attributes.attribute(AndroidArtifacts.ARTIFACT_TYPE, AndroidArtifacts.ArtifactType.CLASSES_JAR.type)
variant.attributes.attributeProvider(
AndroidArtifacts.ARTIFACT_TYPE,
project.provider { AndroidArtifacts.ArtifactType.CLASSES_JAR.type }
)
variant.artifact(mainCompilation.output.classesDirs.singleFile) {
it.builtBy(mainCompilation.output.classesDirs)
}
@@ -41,14 +41,26 @@ internal fun PrototypeAndroidTarget.createAndroidCompilation(name: String): Prot
configure { compilation ->
/* Setup attributes for the compile dependencies */
compilation.configurations.compileDependencyConfiguration.apply {
attributes.attribute(ARTIFACT_TYPE, AndroidArtifacts.ArtifactType.CLASSES_JAR.type)
attributes.attribute(TARGET_JVM_ENVIRONMENT_ATTRIBUTE, project.objects.named(TargetJvmEnvironment.ANDROID))
attributes.attributeProvider(
ARTIFACT_TYPE,
project.provider { AndroidArtifacts.ArtifactType.CLASSES_JAR.type }
)
attributes.attributeProvider(
TARGET_JVM_ENVIRONMENT_ATTRIBUTE,
project.provider { project.objects.named(TargetJvmEnvironment.ANDROID) }
)
}
/* Setup attributes for the runtime dependencies */
compilation.configurations.runtimeDependencyConfiguration?.apply {
attributes.attribute(ARTIFACT_TYPE, AndroidArtifacts.ArtifactType.CLASSES_JAR.type)
attributes.attribute(TARGET_JVM_ENVIRONMENT_ATTRIBUTE, project.objects.named(TargetJvmEnvironment.ANDROID))
attributes.attributeProvider(
ARTIFACT_TYPE,
project.provider { AndroidArtifacts.ArtifactType.CLASSES_JAR.type }
)
attributes.attributeProvider(
TARGET_JVM_ENVIRONMENT_ATTRIBUTE,
project.provider { project.objects.named(TargetJvmEnvironment.ANDROID) }
)
}
}
}