|
| 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 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('NEXUS_USERNAME') ? NEXUS_USERNAME : "" |
| 39 | +} |
| 40 | + |
| 41 | +def getRepositoryPassword() { |
| 42 | + return 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 = POM_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 | + android.libraryVariants.all { variant -> |
| 99 | + def javadocTask = task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) { |
| 100 | + description "Generates Javadoc for $variant.name." |
| 101 | + source = variant.javaCompile.source |
| 102 | + ext.androidJar = project.files(android.getBootClasspath().join(File.pathSeparator)) |
| 103 | + classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar) |
| 104 | + exclude '**/BuildConfig.java' |
| 105 | + exclude '**/R.java' |
| 106 | + } |
| 107 | + |
| 108 | + javadocTask.dependsOn variant.javaCompile |
| 109 | + |
| 110 | + def jarJavadocTask = task("jar${variant.name.capitalize()}Javadoc", type: Jar) { |
| 111 | + description "Generate Javadoc Jar for $variant.name" |
| 112 | + classifier = 'javadoc' |
| 113 | + from javadocTask.destinationDir |
| 114 | + } |
| 115 | + |
| 116 | + jarJavadocTask.dependsOn javadocTask |
| 117 | + artifacts.add('archives', jarJavadocTask) |
| 118 | + |
| 119 | + def jarSourceTask = task("jar${variant.name.capitalize()}Sources", type: Jar) { |
| 120 | + description "Generates Java Sources for $variant.name." |
| 121 | + classifier = 'sources' |
| 122 | + from variant.javaCompile.source |
| 123 | + } |
| 124 | + |
| 125 | + jarSourceTask.dependsOn variant.javaCompile |
| 126 | + artifacts.add('archives', jarSourceTask) |
| 127 | + } |
| 128 | +} |
0 commit comments