[Gradle] IdeBinaryDependencyResolverTest: Add test - android artifact transformation
^KT-56439 Verification Pending
This commit is contained in:
committed by
Space Team
parent
dd2317b1c2
commit
3b75658113
+63
-4
@@ -7,16 +7,20 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.dependencyResolutionTests.tcs
|
||||
|
||||
import com.android.build.gradle.internal.publishing.AndroidArtifacts
|
||||
import org.jetbrains.kotlin.gradle.dependencyResolutionTests.mavenCentralCacheRedirector
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinResolvedBinaryDependency
|
||||
import org.jetbrains.kotlin.gradle.idea.testFixtures.tcs.assertMatches
|
||||
import org.jetbrains.kotlin.gradle.idea.testFixtures.tcs.binaryCoordinates
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.ide.IdeDependencyResolver.Companion.gradleArtifact
|
||||
import org.jetbrains.kotlin.gradle.plugin.ide.dependencyResolvers.IdeBinaryDependencyResolver
|
||||
import org.jetbrains.kotlin.gradle.util.applyMultiplatformPlugin
|
||||
import org.jetbrains.kotlin.gradle.util.buildProject
|
||||
import org.jetbrains.kotlin.gradle.util.enableDefaultStdlibDependency
|
||||
import org.jetbrains.kotlin.gradle.util.enableDependencyVerification
|
||||
import org.jetbrains.kotlin.gradle.util.*
|
||||
import org.jetbrains.kotlin.gradle.utils.androidExtension
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.fail
|
||||
|
||||
class IdeBinaryDependencyResolverTest {
|
||||
|
||||
@@ -77,4 +81,59 @@ class IdeBinaryDependencyResolverTest {
|
||||
IdeBinaryDependencyResolver().resolve(linuxX64Main).assertMatches(linuxDependencies)
|
||||
IdeBinaryDependencyResolver().resolve(linuxX64Test).assertMatches(linuxDependencies)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test - android artifact transformation`() {
|
||||
assumeAndroidSdkAvailable()
|
||||
|
||||
/* Setup simple project that can resolve MVIKotlin */
|
||||
val project = buildProject {
|
||||
enableDefaultStdlibDependency(false)
|
||||
enableDependencyVerification(false)
|
||||
applyMultiplatformPlugin()
|
||||
plugins.apply("com.android.library")
|
||||
androidExtension.compileSdkVersion(33)
|
||||
repositories.mavenCentralCacheRedirector()
|
||||
}
|
||||
|
||||
/* Setup android target and add MVIKotlin dependency */
|
||||
val kotlin = project.multiplatformExtension
|
||||
kotlin.targetHierarchy.default()
|
||||
kotlin.android()
|
||||
val commonMain = kotlin.sourceSets.getByName("commonMain")
|
||||
commonMain.dependencies {
|
||||
implementation("com.arkivanov.mvikotlin:mvikotlin:3.0.2")
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
/*
|
||||
Resolve dependencies on commonMain with platform attributes from Android,
|
||||
then find the mvikotlin-android dependency (aar)
|
||||
*/
|
||||
val resolvedDependency = IdeBinaryDependencyResolver(
|
||||
artifactResolutionStrategy = IdeBinaryDependencyResolver.ArtifactResolutionStrategy.PlatformLikeSourceSet(
|
||||
setupPlatformResolutionAttributes = {
|
||||
attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm)
|
||||
},
|
||||
setupArtifactViewAttributes = {
|
||||
attribute(AndroidArtifacts.ARTIFACT_TYPE, AndroidArtifacts.ArtifactType.CLASSES_JAR.type)
|
||||
}
|
||||
)
|
||||
).resolve(commonMain).filterIsInstance<IdeaKotlinResolvedBinaryDependency>()
|
||||
.find { it.coordinates?.module == "mvikotlin-android" }
|
||||
?: fail("Missing mvikotlin-android dependency")
|
||||
|
||||
/* Check that the Android dependency got resolved as .jar */
|
||||
if (resolvedDependency.classpath.isEmpty()) fail("Expected at least one file in dependency classpath")
|
||||
resolvedDependency.classpath.forEach { file ->
|
||||
assertEquals("jar", file.extension, "Expected jar file. Found ${file.name}")
|
||||
}
|
||||
|
||||
/* Check if we *really* matched the Android release variant */
|
||||
(resolvedDependency.gradleArtifact ?: fail("Missing gradleArtifact")).let { artifact ->
|
||||
if (!artifact.variant.displayName.endsWith("releaseRuntimeElements-published"))
|
||||
fail("Expected release variant matched. Found ${artifact.variant.displayName}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user