|
2 | 2 | * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
|
3 | 3 | */
|
4 | 4 |
|
| 5 | +import org.gradle.api.* |
5 | 6 | import org.gradle.api.artifacts.transform.InputArtifact
|
6 | 7 | import org.gradle.api.artifacts.transform.TransformAction
|
7 | 8 | import org.gradle.api.artifacts.transform.TransformOutputs
|
8 | 9 | import org.gradle.api.artifacts.transform.TransformParameters
|
| 10 | +import org.gradle.api.attributes.* |
9 | 11 | import org.gradle.api.file.FileSystemLocation
|
10 | 12 | import org.gradle.api.provider.Provider
|
| 13 | +import org.gradle.kotlin.dsl.* |
11 | 14 | import java.io.File
|
12 | 15 | import java.nio.file.Files
|
13 | 16 | import java.util.zip.ZipEntry
|
14 | 17 | import java.util.zip.ZipFile
|
15 | 18 |
|
16 |
| -// TODO move back to kotlinx-coroutines-play-services when it's migrated to the kts |
| 19 | +// Attributes used by aar dependencies |
| 20 | +val artifactType = Attribute.of("artifactType", String::class.java) |
| 21 | +val unpackedAar = Attribute.of("unpackedAar", Boolean::class.javaObjectType) |
| 22 | + |
| 23 | +fun Project.configureAar() = configurations.configureEach { |
| 24 | + afterEvaluate { |
| 25 | + if (isCanBeResolved) { |
| 26 | + attributes.attribute(unpackedAar, true) // request all AARs to be unpacked |
| 27 | + } |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +fun DependencyHandlerScope.configureAarUnpacking() { |
| 32 | + attributesSchema { |
| 33 | + attribute(unpackedAar) |
| 34 | + } |
| 35 | + |
| 36 | + artifactTypes { |
| 37 | + create("aar") { |
| 38 | + attributes.attribute(unpackedAar, false) |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + registerTransform(UnpackAar::class.java) { |
| 43 | + from.attribute(unpackedAar, false).attribute(artifactType, "aar") |
| 44 | + to.attribute(unpackedAar, true).attribute(artifactType, "jar") |
| 45 | + } |
| 46 | +} |
| 47 | + |
17 | 48 | @Suppress("UnstableApiUsage")
|
18 | 49 | abstract class UnpackAar : TransformAction<TransformParameters.None> {
|
19 | 50 | @get:InputArtifact
|
|
0 commit comments