@@ -23,12 +23,14 @@ import java.nio.file.Paths
23
23
import org.gradle.api.Plugin
24
24
import org.gradle.api.Project
25
25
import org.gradle.api.artifacts.ProjectDependency
26
+ import org.gradle.api.provider.Provider
26
27
import org.gradle.api.publish.PublishingExtension
27
28
import org.gradle.api.publish.maven.MavenPom
28
29
import org.gradle.api.publish.maven.MavenPublication
29
30
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
30
31
import org.gradle.api.tasks.TaskProvider
31
32
import org.gradle.kotlin.dsl.apply
33
+ import org.gradle.kotlin.dsl.assign
32
34
import org.gradle.kotlin.dsl.configure
33
35
import org.gradle.kotlin.dsl.create
34
36
import org.gradle.kotlin.dsl.findByType
@@ -37,7 +39,61 @@ import org.gradle.kotlin.dsl.provideDelegate
37
39
import org.gradle.kotlin.dsl.register
38
40
import org.w3c.dom.Element
39
41
42
+ /* *
43
+ * Plugin for Firebase Libraries.
44
+ *
45
+ * Implements shared functionality between Java and Android libraries.
46
+ *
47
+ * @see [FirebaseAndroidLibraryPlugin]
48
+ * @see [FirebaseJavaLibraryPlugin]
49
+ * @see [FirebaseLibraryExtension]
50
+ */
40
51
abstract class BaseFirebaseLibraryPlugin : Plugin <Project > {
52
+ protected fun setupDefaults (project : Project , library : FirebaseLibraryExtension ) {
53
+ with (library) {
54
+ previewMode.convention(" " )
55
+ publishJavadoc.convention(true )
56
+ publishSources.convention(true )
57
+ artifactId.convention(project.name)
58
+ groupId.convention(project.provider { project.group.toString() })
59
+ libraryGroup.convention(artifactId)
60
+
61
+ customizePom {
62
+ licenses {
63
+ license {
64
+ name = " The Apache Software License, Version 2.0"
65
+ url = " http://www.apache.org/licenses/LICENSE-2.0.txt"
66
+ }
67
+ }
68
+ scm {
69
+ connection = " scm:git:https://github.com/firebase/firebase-android-sdk.git"
70
+ url = " https://github.com/firebase/firebase-android-sdk"
71
+ }
72
+ }
73
+
74
+ releaseNotes {
75
+ enabled.convention(true )
76
+ hasKTX.convention(true )
77
+ artifactId.convention(project.name)
78
+ artifactName.convention(project.name)
79
+ }
80
+
81
+ val parent = project.parent
82
+ // TODO(): remove when we get rid of ktx modules
83
+ if (project.name == " ktx" && parent != = null ) {
84
+ artifactId.convention(parent.provider { " ${parent.name} -ktx" })
85
+ groupId.convention(parent.provider { " ${parent.group} " })
86
+ }
87
+
88
+ androidLintCheckProjects.convention(
89
+ project
90
+ .provideProperty<String >(" firebase.checks.lintProjects" )
91
+ .map { it.split(" ," ) }
92
+ .orElse(emptyList())
93
+ )
94
+ }
95
+ }
96
+
41
97
protected fun registerMakeReleaseNotesTask (project : Project ) =
42
98
project.tasks.register<MakeReleaseNotesTask >(" makeReleaseNotes" ) {
43
99
val changelog = project.file(" CHANGELOG.md" )
@@ -59,8 +115,8 @@ abstract class BaseFirebaseLibraryPlugin : Plugin<Project> {
59
115
project.afterEvaluate {
60
116
configurations.all {
61
117
if (" lintChecks" == name) {
62
- for (checkProject in library.staticAnalysis. androidLintCheckProjects) {
63
- project.dependencies.add(" lintChecks" , project.project(checkProject!! ))
118
+ for (checkProject in library.androidLintCheckProjects.get() ) {
119
+ project.dependencies.add(" lintChecks" , project.project(checkProject))
64
120
}
65
121
}
66
122
}
@@ -75,7 +131,7 @@ abstract class BaseFirebaseLibraryPlugin : Plugin<Project> {
75
131
Paths .get(
76
132
project.rootProject.buildDir.path,
77
133
" apiinfo" ,
78
- project.path.substring(1 ).replace(" :" , " _" )
134
+ project.path.substring(1 ).replace(" :" , " _" ),
79
135
)
80
136
)
81
137
val outputApiFile = File (outputFile.absolutePath + " _api.txt" )
@@ -122,23 +178,26 @@ abstract class BaseFirebaseLibraryPlugin : Plugin<Project> {
122
178
* configures maven pom generation.
123
179
*
124
180
* @see [applyPomTransformations]
125
- * @see [FirebaseLibraryExtension.applyPomCustomization ]
181
+ * @see [FirebaseLibraryExtension.customizePomAction ]
126
182
*/
127
183
protected fun configurePublishing (project : Project , firebaseLibrary : FirebaseLibraryExtension ) {
128
184
with (project) {
129
185
apply<MavenPublishPlugin >()
186
+
187
+ // TODO(b/371625225): sources jar is missing from java libs
130
188
extensions.configure<PublishingExtension > {
131
189
repositories.maven {
132
190
url = rootProject.fileFromBuildDir(" m2repository" ).toURI()
133
191
name = " BuildDir"
134
192
}
135
193
publications.create<MavenPublication >(" mavenAar" ) {
194
+ // TODO(https://github.com/gradle/gradle/issues/18619): Remove afterEvaluate when
195
+ // properties are supported
136
196
afterEvaluate {
137
- artifactId =
138
- firebaseLibrary.artifactId.get() // these dont get populated until afterEvaluate :(
197
+ artifactId = firebaseLibrary.artifactId.get()
139
198
groupId = firebaseLibrary.groupId.get()
140
199
141
- firebaseLibrary.applyPomCustomization(pom )
200
+ pom( firebaseLibrary.customizePomAction )
142
201
firebaseLibrary.applyPomTransformations(pom)
143
202
from(components.findByName(firebaseLibrary.type.componentName))
144
203
}
@@ -155,7 +214,6 @@ abstract class BaseFirebaseLibraryPlugin : Plugin<Project> {
155
214
* @param pom the [MavenPom] to prepare
156
215
* @see [addTypeWithAARSupport]
157
216
*/
158
- // TODO(b/270576405): Combine with applyPomCustomization when migrating FirebaseLibraryExtension
159
217
private fun FirebaseLibraryExtension.applyPomTransformations (pom : MavenPom ) {
160
218
pom.withXml {
161
219
val dependencies = asElement().findElementsByTag(" dependency" )
@@ -198,7 +256,7 @@ abstract class BaseFirebaseLibraryPlugin : Plugin<Project> {
198
256
/* *
199
257
* A list of _all_ dependencies that publish `aar` artifacts.
200
258
*
201
- * This is collected via the [runtimeClasspath][FirebaseLibraryExtension.getRuntimeClasspath ], and
259
+ * This is collected via the [runtimeClasspath][FirebaseLibraryExtension.runtimeClasspath ], and
202
260
* includes project level dependencies as well as external dependencies.
203
261
*
204
262
* The dependencies are mapped to their [mavenName][toMavenName].
@@ -209,15 +267,17 @@ abstract class BaseFirebaseLibraryPlugin : Plugin<Project> {
209
267
// TODO(b/277607560): Remove when Gradle's MavenPublishPlugin adds functionality for aar types
210
268
fun FirebaseLibraryExtension.resolveAndroidDependencies () =
211
269
resolveExternalAndroidLibraries() +
212
- resolveProjectLevelDependencies().filter { it.type == LibraryType .ANDROID }.map { it.mavenName }
270
+ resolveProjectLevelDependencies()
271
+ .filter { it.type == LibraryType .ANDROID }
272
+ .map { it.mavenName.get() }
213
273
214
274
/* *
215
275
* A list of project level dependencies.
216
276
*
217
- * This is collected via the [runtimeClasspath][FirebaseLibraryExtension.getRuntimeClasspath ].
277
+ * This is collected via the [runtimeClasspath][FirebaseLibraryExtension.runtimeClasspath ].
218
278
*
219
279
* @throws RuntimeException if a project level dependency is found that doesn't have
220
- * [FirebaseLibraryExtension]
280
+ * [FirebaseLibraryExtension]
221
281
*/
222
282
// TODO(b/277607560): Remove when Gradle's MavenPublishPlugin adds functionality for aar types
223
283
fun FirebaseLibraryExtension.resolveProjectLevelDependencies () =
@@ -264,16 +324,23 @@ fun FirebaseLibraryExtension.resolveExternalAndroidLibraries() =
264
324
* ```
265
325
* "com.google.firebase:firebase-common:16.0.5"
266
326
* ```
327
+ *
328
+ * @see [mavenName]
267
329
*/
268
330
val FirebaseLibraryExtension .artifactName: String
269
- get() = " $mavenName :$version "
331
+ get() = " ${ mavenName.get()} :$version "
270
332
271
333
/* *
272
334
* Fetches the latest version for this SDK from GMaven.
273
335
*
274
336
* Uses [GmavenHelper] to make the request.
337
+ *
338
+ * To get the latest released version per the local `gradle.properties`, use [latestReleasedVersion]
339
+ * .
340
+ *
341
+ * @see [ModuleVersion]
275
342
*/
276
- val FirebaseLibraryExtension .latestVersion : ModuleVersion
343
+ val FirebaseLibraryExtension .latestGMavenVersion : ModuleVersion
277
344
get() {
278
345
val latestVersion = GmavenHelper (groupId.get(), artifactId.get()).getLatestReleasedVersion()
279
346
@@ -283,6 +350,22 @@ val FirebaseLibraryExtension.latestVersion: ModuleVersion
283
350
)
284
351
}
285
352
353
+ /* *
354
+ * The latest version released, per the `gradle.properties` file.
355
+ *
356
+ * Checks for the property `latestReleasedVersion`, which should be in the `gradle.properties` files
357
+ * of released SDKs (alongside the current `version`).
358
+ *
359
+ * To fetch the latest released version per GMaven, use [latestGMavenVersion].
360
+ *
361
+ * ```properties
362
+ * version=19.2.1
363
+ * latestReleasedVersion=19.2.0
364
+ * ```
365
+ */
366
+ val FirebaseLibraryExtension .latestReleasedVersion: Provider <String >
367
+ get() = project.provideProperty<String >(" latestReleasedVersion" )
368
+
286
369
/* *
287
370
* Fetches the namespace for this SDK from the [LibraryExtension].
288
371
*
@@ -298,3 +381,16 @@ val FirebaseLibraryExtension.namespace: String
298
381
get() =
299
382
project.extensions.getByType<LibraryExtension >().namespace
300
383
? : throw RuntimeException (" Project doesn't have a defined namespace: ${project.path} " )
384
+
385
+ /* *
386
+ * The name of this library on maven, without the version.
387
+ *
388
+ * For example, the following could be a maven name:
389
+ * ```
390
+ * "com.google.firebase:firebase-common"
391
+ * ```
392
+ *
393
+ * @see [artifactName]
394
+ */
395
+ val FirebaseLibraryExtension .mavenName: Provider <String >
396
+ get() = groupId.zip(artifactId) { groupId, artifactId -> " $groupId :$artifactId " }
0 commit comments