[Gradle] Fix friendArtifactResolver for External Targets API
It was failing with ClassCastException in an attempt of using it. Also added a test case to cover the logic with friendArtifactResolver ^KT-66431 Verification Pending
This commit is contained in:
committed by
Space Team
parent
5873127342
commit
e2336e1752
+3
@@ -7,6 +7,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.android
|
||||
|
||||
import org.gradle.api.file.ConfigurableFileCollection
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
|
||||
@@ -27,5 +28,7 @@ class PrototypeAndroidCompilation(delegate: Delegate) : DecoratedExternalKotlinC
|
||||
get() = super.compilerOptions as HasCompilerOptions<KotlinJvmCompilerOptions>
|
||||
|
||||
var androidCompilationSpecificStuff = 10
|
||||
|
||||
val extraFriendPaths: ConfigurableFileCollection = project.files()
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -25,6 +25,10 @@ internal fun PrototypeAndroidTarget.createAndroidCompilation(name: String): Prot
|
||||
compilationFactory = CompilationFactory(::PrototypeAndroidCompilation)
|
||||
compileTaskName = camelCase("prototype", "compile", targetName, name)
|
||||
|
||||
friendArtifactResolver = ExternalKotlinCompilationDescriptor.FriendArtifactResolver { compilation ->
|
||||
compilation.extraFriendPaths
|
||||
}
|
||||
|
||||
/*
|
||||
Replace Kotlin's compilation association (main <-> test) with noop,
|
||||
since Android goes through adding a dependency on the project itself
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ fun <T : DecoratedExternalKotlinCompilation> DecoratedExternalKotlinTarget.creat
|
||||
descriptor.friendArtifactResolver?.let { declaredResolver ->
|
||||
DefaultKotlinCompilationFriendPathsResolver.FriendArtifactResolver { compilation ->
|
||||
@Suppress("unchecked_cast")
|
||||
declaredResolver.resolveFriendPaths(compilation as T)
|
||||
declaredResolver.resolveFriendPaths(compilation.decoratedInstance as T)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
+46
@@ -16,9 +16,12 @@ import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.idea.testFixtures.tcs.anyDependency
|
||||
import org.jetbrains.kotlin.gradle.idea.testFixtures.tcs.assertMatches
|
||||
import org.jetbrains.kotlin.gradle.idea.testFixtures.tcs.binaryCoordinates
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.default
|
||||
import org.jetbrains.kotlin.gradle.plugin.ide.kotlinIdeMultiplatformImport
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.util.*
|
||||
import org.jetbrains.kotlin.gradle.utils.getByType
|
||||
import org.jetbrains.kotlin.util.assertDoesNotThrow
|
||||
import org.junit.Test
|
||||
import kotlin.test.BeforeTest
|
||||
import kotlin.test.assertEquals
|
||||
@@ -96,4 +99,47 @@ class ExternalAndroidTargetPrototypeSmokeTest {
|
||||
anyDependency()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test compile task arguments created without failures`() {
|
||||
val project = buildProject {
|
||||
enableDefaultStdlibDependency(false)
|
||||
enableDependencyVerification(false)
|
||||
applyMultiplatformPlugin()
|
||||
repositories.mavenLocal()
|
||||
repositories.mavenCentralCacheRedirector()
|
||||
}
|
||||
setAndroidSdkDirProperty(project)
|
||||
project.androidLibrary { compileSdk = 31 }
|
||||
val androidTargetPrototype = project.multiplatformExtension.androidTargetPrototype()
|
||||
project.evaluate()
|
||||
|
||||
androidTargetPrototype.compilations.forEach { compilation ->
|
||||
val compileTask = compilation.compileTaskProvider.get() as KotlinCompile
|
||||
assertDoesNotThrow { compileTask.createCompilerArguments(default) }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test extra friend-path is added correctly to compiler args`() {
|
||||
val project = buildProject {
|
||||
enableDefaultStdlibDependency(false)
|
||||
enableDependencyVerification(false)
|
||||
applyMultiplatformPlugin()
|
||||
repositories.mavenLocal()
|
||||
repositories.mavenCentralCacheRedirector()
|
||||
}
|
||||
setAndroidSdkDirProperty(project)
|
||||
project.androidLibrary { compileSdk = 31 }
|
||||
val androidTargetPrototype = project.multiplatformExtension.androidTargetPrototype()
|
||||
project.evaluate()
|
||||
|
||||
val unitTest = androidTargetPrototype.compilations.getByName("unitTest")
|
||||
val file = project.file("foo.jar")
|
||||
unitTest.extraFriendPaths.from(file)
|
||||
|
||||
val compileTask = unitTest.compileTaskProvider.get() as KotlinCompile
|
||||
val args = compileTask.createCompilerArguments(default)
|
||||
if (file.absolutePath !in args.friendPaths!!) fail("File $file was not found int the friend paths ${args.friendPaths!!.toList()}")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user