1+
2+ apply plugin : " maven-publish"
3+ apply plugin : " signing"
4+
5+ task androidJavaDoc (type : Javadoc ) {
6+ source = android. sourceSets. main. java. srcDirs
7+ classpath + = project. files(android. getBootClasspath(). join(File . pathSeparator))
8+ options. encoding " UTF-8"
9+ options. charSet ' UTF-8'
10+ options. author true
11+ options. version true
12+ failOnError false
13+ }
14+
15+ task androidJavaDocJar (type : Jar , dependsOn : androidJavaDoc) {
16+ archiveClassifier. set(' javadoc' )
17+ from androidJavaDoc. destinationDir
18+ }
19+
20+ task androidSourcesJar (type : Jar ) {
21+ archiveClassifier. set(' sources' )
22+ from android. sourceSets. main. java. srcDirs
23+ }
24+
25+ /**
26+ * Helper to add dependencies to the POM node. This is needed during manual construction
27+ * of the dependencies block
28+ */
29+ static def addPomDependency (groovy.util.Node dependenciesNode , Dependency dependency , String dependencyScope ) {
30+ // Ignore incomplete dependencies
31+ if (dependency. name == null || dependency. name == ' unspecified' || dependency. group == null || dependency. version == null ) {
32+ return
33+ }
34+
35+ def dependencyNode = dependenciesNode. appendNode(' dependency' )
36+ dependencyNode. appendNode(' groupId' , dependency. group)
37+ dependencyNode. appendNode(' artifactId' , dependency. name)
38+ dependencyNode. appendNode(' version' , dependency. version)
39+ dependencyNode. appendNode(' scope' , dependencyScope)
40+ }
41+
42+ /**
43+ * Deploy to Maven Central (Sonatype)
44+ * `$ ./gradlew clean library:assembleRelease androidJavaDocJar androidSourcesJar generatePomFileForNexusPublication publishNexusPublicationToSonatypeRepository closeSonatypeStagingRepository`
45+ *
46+ * ** NOTE: **
47+ * This expects the following environment variables to be present
48+ * - `SONATYPE_TOKEN_USERNAME` : The username for the user token in Sonatype
49+ * - `SONATYPE_TOKEN_PASSWORD` : The password for the user token in Sonatype
50+ * - `SIGNING_KEY_ID` : The ID for the GPG signing key to sign the library with
51+ * - `SIGNING_KEY` : The GPG key to sign the library with
52+ * - `SIGNING_KEY_PASSWORD` : The password for the `SIGNING_KEY`
53+ */
54+ publishing {
55+ publications {
56+ nexus(MavenPublication ) {
57+ groupId rootProject. ext. libraryInfo. groupId
58+ artifactId rootProject. ext. libraryInfo. artifactId
59+ version rootProject. ext. libraryInfo. versionName
60+
61+ artifact bundleReleaseAar
62+ artifact androidJavaDocJar
63+ artifact androidSourcesJar
64+
65+ pom {
66+ name = rootProject. ext. libraryInfo. groupId + " :" + rootProject. ext. libraryInfo. artifactId
67+ description = " A media playback management library for Android"
68+ url = " https://github.com/brianwernick/PlaylistCore"
69+ licenses {
70+ license {
71+ name = " The Apache License, Version 2.0"
72+ url = " http://www.apache.org/licenses/LICENSE-2.0.txt"
73+ }
74+ }
75+ scm {
76+ connection = ' scm:git:github.com/brianwernick/PlaylistCore.git'
77+ developerConnection = ' scm:git:ssh://github.com/brianwernick/PlaylistCore.git'
78+ url = ' https://github.com/brianwernick/PlaylistCore/tree/main'
79+ }
80+ developers {
81+ developer {
82+ name = ' Brian Wernick'
83+ email = ' brian@devbrackets.com'
84+ organization = ' DevBrackets'
85+ organizationUrl = ' https://devbrackets.com'
86+ }
87+ }
88+
89+ // The generated POM doesn't include dependencies when building Android artifacts, so we manually
90+ // add the dependencies to the POM here
91+ withXml {
92+ def dependenciesNode = asNode(). appendNode(' dependencies' )
93+
94+ // Iterate over the implementation dependencies, adding a <dependency> node for each
95+ configurations. implementation. dependencies. each {
96+ addPomDependency(dependenciesNode, it, " runtime" )
97+ }
98+
99+ // Iterate over the api dependencies, adding a <dependency> node for each
100+ configurations. api. dependencies. each {
101+ addPomDependency(dependenciesNode, it, " compile" )
102+ }
103+ }
104+ }
105+ }
106+ }
107+ }
108+
109+ signing {
110+ useInMemoryPgpKeys(
111+ System . getenv(" SIGNING_KEY_ID" ),
112+ System . getenv(" SIGNING_KEY" ),
113+ System . getenv(" SIGNING_KEY_PASSWORD" ),
114+ )
115+
116+ sign publishing. publications. nexus
117+ }
0 commit comments