-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathpublish-artifacts-to-maven-repo.gradle
141 lines (126 loc) · 5.15 KB
/
publish-artifacts-to-maven-repo.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
apply plugin: 'maven-publish'
apply plugin: 'signing'
/**
* Uses the maven-publish plugin and a few custom tasks in order to generate, sign and publish
* artifacts to the remote Maven repo defined inside expandableFabRelease (near bottom of page).
*
* Artifacts generated:
* 1) Library AAR
* 2) Source code JAR
* 3) Documentation (JavaDoc, KDoc) in separate JARs
* 4) The Gradle Module Metadata file
* 5) The Maven POM file
*
* NOTE: Because of the issue described in 'generate-docs-and-update-website.gradle', we need to
* run the 'publish' task without the Gradle Daemon. See the cmd below:
*
* ./gradlew --no-daemon clean publish
*
* Resources:
* https://docs.gradle.org/current/userguide/publishing_setup.html (starting page of the guide)
* https://docs.gradle.org/current/userguide/publishing_signing.html
* https://docs.gradle.org/current/userguide/signing_plugin.html#sec:signatory_credentials
* https://docs.gradle.org/current/userguide/publishing_maven.html
* https://developer.android.com/studio/build/maven-publish-plugin
* */
def mavenGroupId = "com.nambimobile.widgets"
def mavenArtifactId = archivesBaseName
def mavenVersion = android.defaultConfig.versionName
/**
* Although also set in the MavenPublication task at the bottom of this page, version also needs to
* be set here as some artifact generating tasks need it when constructing file names.
* Example: generateJavaDocJar task generates a file named expandable-fab-[version]-javadoc.jar
* */
version = mavenVersion
/**
* Generates JAR artifacts for the documentation formats we support (see
* 'generate-docs-and-update-website.gradle')
* */
task generateJavaDocJar(type: Jar){
dependsOn dokkaJavadoc
archiveClassifier.set('javadoc')
from javadocOutputDirectory.getAbsolutePath() // see 'generate-docs-and-update-website.gradle'
}
task generateKDocJar(type: Jar){
dependsOn dokkaHtml
archiveClassifier.set('kdoc')
from kdocOutputDirectory.getAbsolutePath() // see 'generate-docs-and-update-website.gradle'
}
/** Generates a JAR of our source code. **/
task generateSourcesJar(type: Jar){
archiveClassifier.set('sources')
from android.sourceSets.main.java.srcDirs
}
/**
* Uses GnupgSignatory for signing every artifact within our maven publication defined below.
* Password for the secret key will be pulled from the locally running gpg-agent for security
* (other less sensitive properties it needs are still stored in your global gradle.properties).
* */
signing {
useGpgCmd()
sign publishing.publications
}
/**
* Creates a MavenPublication to assemble and deploy our artifacts and signatures to the repository
* specified. Wrapped in 'afterEvaluate' as it's a requirement from the Android Gradle plugin if
* wanting to use their AAR generated by 'from components.release':
* https://developer.android.com/studio/build/maven-publish-plugin
*
* To run:
*./gradlew --no-daemon clean publish
* */
afterEvaluate {
publishing {
publications {
expandableFabRelease(MavenPublication) {
groupId = mavenGroupId
artifactId = mavenArtifactId
version = mavenVersion
// Includes the library's release AAR to list of artifacts to be published
from components.release
// Adds our other artifacts to list to be published
artifact generateJavaDocJar
artifact generateKDocJar
artifact generateSourcesJar
// Repo to publish signed artifacts to. Credentials stored in global gradle.properties
repositories {
maven {
name = "Sonatype OSSRH (Nexus)"
url = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
credentials {
username = ossrhUsername
password = ossrhPassword
}
}
}
// Metadata required by Maven Central for hosting. Stored in gradle.properties.
// https://central.sonatype.org/pages/requirements.html#sufficient-metadata
pom {
name = POM_NAME
description = POM_DESCRIPTION
url = POM_URL
packaging = POM_PACKAGING
licenses {
license {
name = POM_LICENSE_NAME
url = POM_LICENSE_URL
distribution = POM_LICENSE_DISTRIBUTION
}
}
developers {
developer {
name = POM_DEVELOPER_NAME
organization = POM_DEVELOPER_ORGANIZATION
organizationUrl = POM_DEVELOPER_URL
}
}
scm {
connection = POM_SCM_CONNECTION
developerConnection = POM_SCM_DEVELOPER_CONNECTION
url = POM_SCM_URL
}
}
}
}
}
}