1+ /*
2+ * Copyright 2013 Chris Banes
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ apply plugin : ' maven'
18+ apply plugin : ' signing'
19+
20+ version = VERSION_NAME
21+ group = GROUP
22+
23+ def isReleaseBuild () {
24+ return VERSION_NAME . contains(" SNAPSHOT" ) == false
25+ }
26+
27+ def getReleaseRepositoryUrl () {
28+ return hasProperty(' RELEASE_REPOSITORY_URL' ) ? RELEASE_REPOSITORY_URL
29+ : " https://oss.sonatype.org/service/local/staging/deploy/maven2/"
30+ }
31+
32+ def getSnapshotRepositoryUrl () {
33+ return hasProperty(' SNAPSHOT_REPOSITORY_URL' ) ? SNAPSHOT_REPOSITORY_URL
34+ : " https://oss.sonatype.org/content/repositories/snapshots/"
35+ }
36+
37+ def getRepositoryUsername () {
38+ return hasProperty(' USERNAME' ) ? USERNAME : (hasProperty(' NEXUS_USERNAME' )? NEXUS_USERNAME : " " )
39+ }
40+
41+ def getRepositoryPassword () {
42+ return hasProperty(' PASSWORD' ) ? PASSWORD : (hasProperty(' NEXUS_PASSWORD' )? NEXUS_PASSWORD : " " )
43+ }
44+
45+ afterEvaluate { project ->
46+ uploadArchives {
47+ repositories {
48+ mavenDeployer {
49+ beforeDeployment { MavenDeployment deployment -> signing. signPom(deployment) }
50+
51+ pom. groupId = GROUP
52+ pom. artifactId = POM_ARTIFACT_ID
53+ pom. version = VERSION_NAME
54+
55+ repository(url : getReleaseRepositoryUrl()) {
56+ authentication(userName : getRepositoryUsername(), password : getRepositoryPassword())
57+ }
58+ snapshotRepository(url : getSnapshotRepositoryUrl()) {
59+ authentication(userName : getRepositoryUsername(), password : getRepositoryPassword())
60+ }
61+
62+ pom. project {
63+ name POM_NAME
64+ packaging POM_PACKAGING
65+ description POM_DESCRIPTION
66+ url POM_URL
67+
68+ scm {
69+ url POM_SCM_URL
70+ connection POM_SCM_CONNECTION
71+ developerConnection POM_SCM_DEV_CONNECTION
72+ }
73+
74+ licenses {
75+ license {
76+ name POM_LICENCE_NAME
77+ url POM_LICENCE_URL
78+ distribution POM_LICENCE_DIST
79+ }
80+ }
81+
82+ developers {
83+ developer {
84+ id POM_DEVELOPER_ID
85+ name POM_DEVELOPER_NAME
86+ }
87+ }
88+ }
89+ }
90+ }
91+ }
92+
93+ signing {
94+ required { isReleaseBuild() && gradle. taskGraph. hasTask(" uploadArchives" ) }
95+ sign configurations. archives
96+ }
97+
98+ if (project. getPlugins(). hasPlugin(' com.android.application' ) || project. getPlugins(). hasPlugin(' com.android.library' )) {
99+ task install(type : Upload , dependsOn : assemble) {
100+ repositories. mavenInstaller {
101+ configuration = configurations. archives
102+
103+ pom. groupId = GROUP
104+ pom. artifactId = POM_ARTIFACT_ID
105+ pom. version = VERSION_NAME
106+
107+ pom. project {
108+ name POM_NAME
109+ packaging POM_PACKAGING
110+ description POM_DESCRIPTION
111+ url POM_URL
112+
113+ scm {
114+ url POM_SCM_URL
115+ connection POM_SCM_CONNECTION
116+ developerConnection POM_SCM_DEV_CONNECTION
117+ }
118+
119+ licenses {
120+ license {
121+ name POM_LICENCE_NAME
122+ url POM_LICENCE_URL
123+ distribution POM_LICENCE_DIST
124+ }
125+ }
126+
127+ developers {
128+ developer {
129+ id POM_DEVELOPER_ID
130+ name POM_DEVELOPER_NAME
131+ }
132+ }
133+ }
134+ }
135+ }
136+
137+ task androidJavadocs(type : Javadoc ) {
138+ failOnError false
139+ source = android. sourceSets. main. java. source
140+ classpath + = project. files(android. getBootClasspath(). join(File . pathSeparator))
141+ }
142+
143+ task androidJavadocsJar(type : Jar , dependsOn : androidJavadocs) {
144+ classifier = ' javadoc'
145+ from androidJavadocs. destinationDir
146+ }
147+
148+ task androidSourcesJar(type : Jar ) {
149+ classifier = ' sources'
150+ from android. sourceSets. main. java. source
151+ }
152+ } else {
153+ install {
154+ repositories. mavenInstaller {
155+ pom. groupId = GROUP
156+ pom. artifactId = POM_ARTIFACT_ID
157+ pom. version = VERSION_NAME
158+
159+ pom. project {
160+ name POM_NAME
161+ packaging POM_PACKAGING
162+ description POM_DESCRIPTION
163+ url POM_URL
164+
165+ scm {
166+ url POM_SCM_URL
167+ connection POM_SCM_CONNECTION
168+ developerConnection POM_SCM_DEV_CONNECTION
169+ }
170+
171+ licenses {
172+ license {
173+ name POM_LICENCE_NAME
174+ url POM_LICENCE_URL
175+ distribution POM_LICENCE_DIST
176+ }
177+ }
178+
179+ developers {
180+ developer {
181+ id POM_DEVELOPER_ID
182+ name POM_DEVELOPER_NAME
183+ }
184+ }
185+ }
186+ }
187+ }
188+
189+ task sourcesJar(type : Jar , dependsOn :classes) {
190+ classifier = ' sources'
191+ from sourceSets. main. allSource
192+ }
193+
194+ task javadocJar(type : Jar , dependsOn :javadoc) {
195+ classifier = ' javadoc'
196+ from javadoc. destinationDir
197+ }
198+ }
199+
200+ artifacts {
201+ if (project. getPlugins(). hasPlugin(' com.android.application' ) || project. getPlugins(). hasPlugin(' com.android.library' )) {
202+ archives androidSourcesJar
203+ archives androidJavadocsJar
204+ } else {
205+ archives sourcesJar
206+ archives javadocJar
207+ }
208+ }
209+ }
0 commit comments