1 /*
<lambda>null2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.build.importMaven
18 
19 import org.gradle.api.artifacts.ComponentMetadataContext
20 import org.gradle.api.artifacts.ComponentMetadataRule
21 
22 /**
23  * Some artifacts don't get resolved via configuration attributes.
24  * e.g. sources:
25  *   https://github.com/gradle/gradle/commit/94b266dc50b5fd7dd5460d6d32ff66eab3740627
26  *
27  * We use this ComponentMetadataRule to add them.
28  */
29 class CustomMetadataRules : ComponentMetadataRule {
30     override fun execute(context: ComponentMetadataContext) {
31         val id = context.details.id
32         context.details.allVariants { variantMetadata ->
33             variantMetadata.withFiles {
34                 // sources do not always get resolved for nested dependencies
35                 it.addFile("${id.name}-${id.version}-sources.jar")
36                 // if it does not have gradle metadata, we might miss aar; add it
37                 it.addFile("${id.name}-${id.version}.aar")
38                 // if it does not have gradle metadata, we might miss klib; add it
39                 it.addFile("${id.name}-${id.version}.klib")
40                 // pom.asc files are not always resolved when .module files are present
41                 it.addFile("${id.name}-${id.version}.pom.asc")
42             }
43         }
44     }
45 }
46