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+ Properties properties = new Properties ()
21+ properties. load(project. rootProject. file(' local.properties' ). newDataInputStream())
22+
23+ def isReleaseBuild () {
24+ return libraryVersion. 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(' NEXUS_USERNAME' ) ? NEXUS_USERNAME : " "
39+ }
40+
41+ def getRepositoryPassword () {
42+ return hasProperty(' NEXUS_PASSWORD' ) ? NEXUS_PASSWORD : " "
43+ }
44+
45+ def keyID = properties. getProperty(" signing.keyId" )
46+ def password = properties. getProperty(" signing.password" )
47+ def keyRingLocation = properties. getProperty(" signing.secretKeyRingFile" )
48+ def nexus_username = properties. getProperty(" NEXUS_USERNAME" )
49+ def nexus_password = properties. getProperty(" NEXUS_PASSWORD" )
50+
51+ ext. " signing.keyId" = keyID
52+ ext. " signing.secretKeyRingFile" = keyRingLocation
53+ ext. " signing.password" = password
54+
55+ afterEvaluate { project ->
56+ uploadArchives {
57+ repositories {
58+ mavenDeployer {
59+ beforeDeployment { MavenDeployment deployment -> signing. signPom(deployment) }
60+
61+ pom. groupId = GROUP
62+ pom. artifactId = libraryName
63+ pom. version = libraryVersion
64+
65+ repository(url : getReleaseRepositoryUrl()) {
66+ authentication(userName : nexus_username, password : nexus_password)
67+ }
68+ snapshotRepository(url : getSnapshotRepositoryUrl()) {
69+ authentication(userName : getRepositoryUsername(), password : getRepositoryPassword())
70+ }
71+
72+ pom. project {
73+ name libraryName
74+ packaging POM_PACKAGING
75+ description POM_DESCRIPTION
76+ url POM_URL
77+
78+ scm {
79+ url POM_SCM_URL
80+ connection POM_SCM_CONNECTION
81+ developerConnection POM_SCM_DEV_CONNECTION
82+ }
83+
84+ licenses {
85+ license {
86+ name POM_LICENCE_NAME
87+ url POM_LICENCE_URL
88+ distribution POM_LICENCE_DIST
89+ }
90+ }
91+
92+ developers {
93+ developer {
94+ id POM_DEVELOPER_ID
95+ name POM_DEVELOPER_NAME
96+ }
97+ }
98+ }
99+ }
100+ }
101+ }
102+
103+ signing {
104+ // required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
105+ required true
106+ sign configurations. archives
107+ }
108+
109+
110+ task androidSourcesJar(type : Jar ) {
111+ classifier = ' sources'
112+ from android. sourceSets. main. java. sourceFiles
113+ }
114+
115+ artifacts {
116+ archives androidSourcesJar
117+ }
118+ }
0 commit comments