Skip to content

Commit 4a83929

Browse files
committed
Centralize publishing so that we can upgrade gradle plugin version
Bug: 28535612 Change-Id: I09e180e3c3cf75e53b933de4fea65e43afd72a00
1 parent 15d428c commit 4a83929

File tree

3 files changed

+132
-162
lines changed

3 files changed

+132
-162
lines changed

build.gradle

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
mavenLocal()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:1.5.0'
9+
classpath 'com.android.tools.build:gradle:2.0.0'
1010
classpath 'com.google.gms:google-services:3.0.0'
1111

1212
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
@@ -29,16 +29,18 @@ allprojects { project ->
2929

3030
// Get constants, this is where we store things
3131
// like the list of submodules or the version
32-
apply from: "$rootDir/common/constants.gradle"
32+
project.apply from: "$rootDir/common/constants.gradle"
3333

3434
def isLibrary = 'library'.equals(project.name)
3535
def isSubmodule = project.ext.submodules.contains(project.name)
36-
def pomTask = "generatePomFileFor${project.name.capitalize()}LibraryPublication"
3736

38-
if (isSubmodule) {
37+
// Only applies to submodules, not the library module
38+
def pomTask = "generatePomFileFor${project.name.capitalize()}LibraryPublication";
39+
40+
if (isSubmodule || isLibrary) {
3941

4042
// So that we can resolve 'android' variable
41-
apply plugin: 'com.android.library'
43+
project.apply plugin: 'com.android.library'
4244
android {
4345
compileSdkVersion 23
4446
buildToolsVersion "${project.ext.buildtools}"
@@ -65,10 +67,7 @@ allprojects { project ->
6567

6668
// Define base name for archives
6769
// Ex: firebase-ui-auth
68-
archivesBaseName = "firebase-ui-${project.name}"
69-
70-
// Convenience tasks that depends on the above
71-
task prepareArtifacts(dependsOn: [javadocJar, sourcesJar, assembleRelease, pomTask]) {}
70+
archivesBaseName = isSubmodule ? "firebase-ui-${project.name}" : "firebase-ui"
7271

7372
// Use tasks above to define artifacts
7473
artifacts {
@@ -77,7 +76,31 @@ allprojects { project ->
7776
}
7877

7978
// So that we can define publication
80-
apply plugin: 'maven-publish'
79+
project.apply plugin: 'maven-publish'
80+
81+
publishing {
82+
// By passing -Pcustom_local=/some/path and running the
83+
// publishLibraryPublicationToCustomLocalRepository task you can publish this library to a
84+
// custom maven repository location on your machine.
85+
repositories {
86+
maven {
87+
name 'CustomLocal'
88+
url uri(project.hasProperty('custom_local') ? project.getProperty('custom_local') : '/tmp/')
89+
}
90+
}
91+
92+
repositories {
93+
maven {
94+
name 'BuildLocal'
95+
url "$buildDir/repo"
96+
}
97+
}
98+
}
99+
}
100+
101+
if (isSubmodule) {
102+
// Convenience task to prepare everything we need for releases
103+
task prepareArtifacts(dependsOn: [javadocJar, sourcesJar, assembleRelease, pomTask]) {}
81104

82105
publishing {
83106

@@ -110,32 +133,48 @@ allprojects { project ->
110133
}
111134
}
112135
}
113-
114136
}
137+
}
138+
}
115139

116-
// By passing -Pcustom_local=/some/path and running the
117-
// publishLibraryPublicationToCustomLocalRepository task you can publish this library to a
118-
// custom maven repository location on your machine.
119-
repositories {
120-
maven {
121-
name 'CustomLocal'
122-
url uri(project.hasProperty('custom_local') ? project.getProperty('custom_local') : '/tmp/')
123-
}
124-
}
140+
if (isLibrary) {
125141

126-
repositories {
127-
maven {
128-
name 'BuildLocal'
129-
url "$buildDir/repo"
142+
// Define the monolith publication
143+
publishing {
144+
145+
publications {
146+
monolithLibrary(MavenPublication) {
147+
groupId project.ext.group
148+
artifactId archivesBaseName
149+
version project.ext.version
150+
151+
artifact "$buildDir/outputs/aar/$archivesBaseName-release.aar"
152+
artifact javadocJar
153+
artifact sourcesJar
154+
155+
// Monolith is just a POM that depends on the others
156+
pom.withXml {
157+
def dependenciesNode = asNode().getAt("dependencies")[0]
158+
if (dependenciesNode == null) {
159+
dependenciesNode = asNode().appendNode("dependencies");
160+
}
161+
162+
// Add a maven dependency on each submodule
163+
project.ext.submodules.each { module ->
164+
def dependencyNode = dependenciesNode.appendNode('dependency')
165+
dependencyNode.appendNode('groupId', project.ext.group)
166+
dependencyNode.appendNode('artifactId', "firebase-ui-${module}")
167+
dependencyNode.appendNode('version', project.ext.version)
168+
}
169+
}
130170
}
131171
}
132-
133172
}
134173
}
135174

136175
// Bintray Configuration (applies to submodule and the monolith)
137176
if (isSubmodule || isLibrary) {
138-
apply plugin: 'com.jfrog.bintray'
177+
project.apply plugin: 'com.jfrog.bintray'
139178

140179
def archivesBaseName = isLibrary ? 'firebase-ui' : "firebase-ui-${project.name}"
141180
def pomLoc = isLibrary ? "$buildDir/publications/monolithLibrary/pom-default.xml" : "$buildDir/publications/${project.name}Library/pom-default.xml"

library/build.gradle

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,70 @@ dependencies {
2626
androidTestCompile 'junit:junit:4.12'
2727
}
2828

29-
apply from: 'publish.gradle'
29+
/**
30+
* Returns list of tasks names that prepareArtfacts should depend on.
31+
*/
32+
def prepareArtifactsTasks() {
33+
return project.ext.submodules.collect { name ->
34+
":${name}:prepareArtifacts"
35+
}.toArray()
36+
}
37+
38+
/**
39+
* Returns list of publish tasks that monolith publish tasks should depend on.
40+
* @param repo relevant repository, such as 'MavenLocal' or 'CustomLocalRepository'
41+
*/
42+
def publishToRepoTasks(repo) {
43+
return project.ext.submodules.collect { name ->
44+
// Ex: name = database, repo = MavenLocal
45+
// Return: :database:publishDatabaseLibraryPublicationToMavenLocal
46+
":${name}:publish${name.capitalize()}LibraryPublicationTo${repo}"
47+
}.toArray()
48+
}
49+
50+
/**
51+
* Returns a list of task names to upload modules to bintray.
52+
*/
53+
def bintrayUploadTasks() {
54+
return project.ext.submodules.collect { name ->
55+
":${name}:bintrayUpload"
56+
}.toArray()
57+
}
58+
59+
/**
60+
* Prepare artifacts for this an all sub-projects.
61+
*/
62+
task prepareArtifacts(dependsOn: [
63+
javadocJar,
64+
sourcesJar,
65+
assembleRelease,
66+
prepareArtifactsTasks(),
67+
"generatePomFileForMonolithLibraryPublication"]) {
68+
}
69+
70+
/**
71+
* Publish all artifacts to the maven local repository.
72+
*/
73+
task publishAllToMavenLocal(dependsOn: [
74+
'publishMonolithLibraryPublicationToMavenLocal',
75+
publishToRepoTasks('MavenLocal')]) {
76+
77+
}
78+
79+
/**
80+
* Publish all artifacts to the customLocal repository.
81+
*/
82+
task publishAllToCustomLocal(dependsOn: [
83+
'publishMonolithLibraryPublicationToCustomLocalRepository',
84+
publishToRepoTasks('CustomLocalRepository')]) {
85+
86+
}
87+
88+
/**
89+
* Upload all artifacts to bintray.
90+
*/
91+
task bintrayUploadAll(dependsOn: [
92+
'bintrayUpload',
93+
bintrayUploadTasks()]) {
94+
95+
}

library/publish.gradle

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)