Skip to content

Commit

Permalink
Update robolectric to workaround robolectric/robolectric#5456 and the…
Browse files Browse the repository at this point in the history
…n workaround all the update consequences
  • Loading branch information
qwwdfsad committed Feb 14, 2022
1 parent cd5cbb9 commit 4b34645
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 50 deletions.
33 changes: 32 additions & 1 deletion buildSrc/src/main/kotlin/UnpackAar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,49 @@
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

import org.gradle.api.*
import org.gradle.api.artifacts.transform.InputArtifact
import org.gradle.api.artifacts.transform.TransformAction
import org.gradle.api.artifacts.transform.TransformOutputs
import org.gradle.api.artifacts.transform.TransformParameters
import org.gradle.api.attributes.*
import org.gradle.api.file.FileSystemLocation
import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.*
import java.io.File
import java.nio.file.Files
import java.util.zip.ZipEntry
import java.util.zip.ZipFile

// TODO move back to kotlinx-coroutines-play-services when it's migrated to the kts
// Attributes used by aar dependencies
val artifactType = Attribute.of("artifactType", String::class.java)
val unpackedAar = Attribute.of("unpackedAar", Boolean::class.javaObjectType)

fun Project.configureAar() = configurations.configureEach {
afterEvaluate {
if (isCanBeResolved) {
attributes.attribute(unpackedAar, true) // request all AARs to be unpacked
}
}
}

fun DependencyHandlerScope.configureAarUnpacking() {
attributesSchema {
attribute(unpackedAar)
}

artifactTypes {
create("aar") {
attributes.attribute(unpackedAar, false)
}
}

registerTransform(UnpackAar::class.java) {
from.attribute(unpackedAar, false).attribute(artifactType, "aar")
to.attribute(unpackedAar, true).attribute(artifactType, "jar")
}
}

@Suppress("UnstableApiUsage")
abstract class UnpackAar : TransformAction<TransformParameters.None> {
@get:InputArtifact
Expand Down
31 changes: 6 additions & 25 deletions integration/kotlinx-coroutines-play-services/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,17 @@

val tasksVersion = "16.0.1"

val artifactType = Attribute.of("artifactType", String::class.java)
val unpackedAar = Attribute.of("unpackedAar", Boolean::class.javaObjectType)

configurations.configureEach {
afterEvaluate {
if (isCanBeResolved) {
attributes.attribute(unpackedAar, true) // request all AARs to be unpacked
}
}
}
project.configureAar()

dependencies {
attributesSchema {
attribute(unpackedAar)
}

artifactTypes {
create("aar") {
attributes.attribute(unpackedAar, false)
}
}

registerTransform(UnpackAar::class.java) {
from.attribute(unpackedAar, false).attribute(artifactType, "aar")
to.attribute(unpackedAar, true).attribute(artifactType, "jar")
}

configureAarUnpacking()
api("com.google.android.gms:play-services-tasks:$tasksVersion") {
exclude(group="com.android.support")
}

// Required by robolectric
testImplementation("androidx.test:core:1.2.0")
testImplementation("androidx.test:monitor:1.2.0")
}

externalDocumentationLink(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

project.configureAar()

dependencies {
configureAarUnpacking()
kotlinCompilerPluginClasspathMain(project(":kotlinx-coroutines-core"))

testImplementation("com.google.android:android:${version("android")}")
testImplementation("org.robolectric:robolectric:${version("robolectric")}")
// Required by robolectric
testImplementation("androidx.test:core:1.2.0")
testImplementation("androidx.test:monitor:1.2.0")

testImplementation(project(":kotlinx-coroutines-test"))
testImplementation(project(":kotlinx-coroutines-android"))
}
26 changes: 2 additions & 24 deletions ui/kotlinx-coroutines-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,10 @@ repositories {
mavenCentral()
}

val artifactType = Attribute.of("artifactType", String::class.java)
val unpackedAar = Attribute.of("unpackedAar", Boolean::class.javaObjectType)

configurations.configureEach {
afterEvaluate {
if (isCanBeResolved) {
attributes.attribute(unpackedAar, true) // request all AARs to be unpacked
}
}
}
project.configureAar()

dependencies {
attributesSchema {
attribute(unpackedAar)
}

artifactTypes {
create("aar") {
attributes.attribute(unpackedAar, false)
}
}

registerTransform(UnpackAar::class.java) {
from.attribute(unpackedAar, false).attribute(artifactType, "aar")
to.attribute(unpackedAar, true).attribute(artifactType, "jar")
}
configureAarUnpacking()

compileOnly("com.google.android:android:${version("android")}")
compileOnly("androidx.annotation:annotation:${version("androidx_annotation")}")
Expand Down

0 comments on commit 4b34645

Please sign in to comment.