@@ -16,6 +16,9 @@ package com.google.firebase.gradle.plugins.publish
16
16
17
17
import org.gradle.api.GradleException
18
18
import org.gradle.api.Project
19
+ import org.gradle.api.artifacts.Configuration
20
+ import org.gradle.api.artifacts.Dependency
21
+ import org.gradle.api.artifacts.ProjectDependency
19
22
import org.gradle.api.publish.maven.MavenPublication
20
23
21
24
/* * Handles publication versioning and pom validation upon release. */
@@ -26,7 +29,7 @@ class Publisher {
26
29
SNAPSHOT
27
30
}
28
31
private final Mode mode;
29
- private final Set<Project > projectsToPublish;
32
+ private final Set<Project > projectsToPublish
30
33
31
34
Publisher (Mode mode , Set<Project > projectsToPublish ) {
32
35
this . mode = mode
@@ -37,6 +40,7 @@ class Publisher {
37
40
publication. pom. withXml {
38
41
def rootNode = asNode()
39
42
validatePomXml(project, rootNode)
43
+ processDependencies(project, rootNode)
40
44
}
41
45
}
42
46
@@ -51,7 +55,7 @@ class Publisher {
51
55
return UNRELEASED_VERSION
52
56
}
53
57
54
- private void validatePomXml (Project p , Node pom ) {
58
+ private static void validatePomXml (Project p , Node pom ) {
55
59
def unreleased = pom. dependencies. dependency. findAll { it. version. text() == UNRELEASED_VERSION }
56
60
.collect { " ${ it.groupId.text()} :${ it.artifactId.text()} " }
57
61
if (unreleased) {
@@ -63,4 +67,53 @@ class Publisher {
63
67
return " ${ baseVersion}${ mode == Mode.SNAPSHOT ? '-SNAPSHOT' : ''} "
64
68
}
65
69
70
+ private static void processDependencies (Project project , Node pom ) {
71
+ def deps = getDependencyTypes(project)
72
+
73
+ pom. dependencies. dependency. each {
74
+ // remove multidex as it is supposed to be added by final applications and is needed for
75
+ // some libraries only for instrumentation tests to build.
76
+ if (it. groupId. text() in [' com.android.support' , ' androidx' ] && it. artifactId. text() == ' multidex' ) {
77
+ it. parent(). remove(it)
78
+ }
79
+ it. appendNode(' type' , [:], deps[" ${ it.groupId.text()} :${ it.artifactId.text()} " ])
80
+
81
+ // change scope to compile to preserve existing behavior
82
+ it. scope. replaceNode {
83
+ createNode(' scope' , ' compile' )
84
+ }
85
+ }
86
+ }
87
+
88
+ private static Map<String , String > getDependencyTypes (Project project ) {
89
+ def dummyDependencyConfiguration = project. configurations. create(' publisherDummyConfig' )
90
+ def nonProjectDependencies = project. configurations. releaseRuntimeClasspath. allDependencies. findAll {
91
+ ! (it instanceof ProjectDependency )
92
+ }
93
+ dummyDependencyConfiguration. dependencies. addAll(nonProjectDependencies)
94
+ try {
95
+ return project. configurations. releaseRuntimeClasspath. getAllDependencies(). collectEntries {
96
+ [(" $it . group :$it . name " as String ): getType(dummyDependencyConfiguration, it)]
97
+ }
98
+ } finally {
99
+ project. configurations. remove(dummyDependencyConfiguration)
100
+ }
101
+
102
+ }
103
+
104
+ private static String getType (Configuration config , Dependency d ) {
105
+ if (d instanceof ProjectDependency ) {
106
+ // we currently only support aar libraries to be produced in this repository
107
+ return ' aar'
108
+ }
109
+ String path = config. find {
110
+ it. absolutePath. matches(" .*\\ Q$d. group /$d. name /$d. version /\\ E[a-zA-Z0-9]+/\\ Q$d. name -$d. version . \\ E[aj]ar" )
111
+ }?. absolutePath
112
+ if (path && path. endsWith (" .aar" )) {
113
+ return " aar"
114
+ } else {
115
+ return " jar"
116
+ }
117
+ }
118
+
66
119
}
0 commit comments