|
| 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 | + * Based on: https://github.com/mcxiaoke/gradle-mvn-push/blob/master/gradle-mvn-push.gradle. |
| 18 | + * |
| 19 | + * To install in a local maven repo: |
| 20 | + * 1. In the project you want to test (not Glide), add mavenLocal() to the repositories list. |
| 21 | + * 2. In Glide, run: ./gradlew uploadArchives -PLOCAL |
| 22 | + * |
| 23 | + * For faster runs add: -x check when building Glide. |
| 24 | + */ |
| 25 | + |
| 26 | +apply plugin: 'maven-publish' |
| 27 | +apply plugin: 'signing' |
| 28 | + |
| 29 | +version = VERSION_NAME |
| 30 | +group = GROUP |
| 31 | + |
| 32 | +static def localMavenRepo() { |
| 33 | + 'file://' + new File(System.getProperty('user.home'), '.m2/repository').absolutePath |
| 34 | +} |
| 35 | + |
| 36 | +@SuppressWarnings("GrMethodMayBeStatic") |
| 37 | +def isReleaseBuild() { |
| 38 | + return !VERSION_NAME.contains("SNAPSHOT") |
| 39 | +} |
| 40 | + |
| 41 | +def getReleaseRepositoryUrl() { |
| 42 | + return hasProperty('LOCAL') ? localMavenRepo() |
| 43 | + : hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL |
| 44 | + //: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/' |
| 45 | + : 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/' |
| 46 | +} |
| 47 | + |
| 48 | +def getSnapshotRepositoryUrl() { |
| 49 | + return hasProperty('LOCAL') ? localMavenRepo() |
| 50 | + : hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL |
| 51 | + //: 'https://oss.sonatype.org/content/repositories/snapshots/' |
| 52 | + : 'https://s01.oss.sonatype.org/content/repositories/snapshots/' |
| 53 | +} |
| 54 | + |
| 55 | +def getRepositoryUsername() { |
| 56 | + return hasProperty('USERNAME') ? USERNAME : (hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : '') |
| 57 | +} |
| 58 | + |
| 59 | +def getRepositoryPassword() { |
| 60 | + return hasProperty('PASSWORD') ? PASSWORD : (hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : '') |
| 61 | +} |
| 62 | + |
| 63 | +def configurePom(pom) { |
| 64 | + pom.name = POM_NAME |
| 65 | + pom.packaging = POM_PACKAGING |
| 66 | + pom.description = POM_DESCRIPTION |
| 67 | + pom.url = POM_URL |
| 68 | + |
| 69 | + pom.scm { |
| 70 | + url = POM_SCM_URL |
| 71 | + connection = POM_SCM_CONNECTION |
| 72 | + developerConnection = POM_SCM_DEV_CONNECTION |
| 73 | + } |
| 74 | + |
| 75 | + pom.licenses { |
| 76 | + license { |
| 77 | + name = POM_LICENCE_NAME |
| 78 | + url = POM_LICENCE_URL |
| 79 | + distribution = POM_LICENCE_DIST |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + pom.developers { |
| 84 | + developer { |
| 85 | + id = POM_DEVELOPER_ID |
| 86 | + name = POM_DEVELOPER_NAME |
| 87 | + } |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +afterEvaluate { project -> |
| 92 | + publishing { |
| 93 | + repositories { |
| 94 | + maven { |
| 95 | + def releasesRepoUrl = getReleaseRepositoryUrl() |
| 96 | + def snapshotsRepoUrl = getSnapshotRepositoryUrl() |
| 97 | + url = isReleaseBuild() ? releasesRepoUrl : snapshotsRepoUrl |
| 98 | + |
| 99 | + credentials(PasswordCredentials) { |
| 100 | + username = getRepositoryUsername() |
| 101 | + password = getRepositoryPassword() |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + if (project.getPlugins().hasPlugin('com.android.application') || |
| 108 | + project.getPlugins().hasPlugin('com.android.library')) { |
| 109 | + |
| 110 | + task androidJavadocs(type: Javadoc) { |
| 111 | + source = android.sourceSets.main.java.source |
| 112 | + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) |
| 113 | + excludes = ['**/*.kt'] |
| 114 | + } |
| 115 | + |
| 116 | + task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { |
| 117 | + classifier = 'javadoc' |
| 118 | + from androidJavadocs.destinationDir |
| 119 | + } |
| 120 | + |
| 121 | + task androidSourcesJar(type: Jar) { |
| 122 | + classifier = 'sources' |
| 123 | + from android.sourceSets.main.java.source |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + if (JavaVersion.current().isJava8Compatible()) { |
| 128 | + allprojects { |
| 129 | + tasks.withType(Javadoc) { |
| 130 | + options.addStringOption('Xdoclint:none', '-quiet') |
| 131 | + } |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + if (JavaVersion.current().isJava9Compatible()) { |
| 136 | + allprojects { |
| 137 | + tasks.withType(Javadoc) { |
| 138 | + options.addBooleanOption('html5', true) |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + artifacts { |
| 144 | + if (project.getPlugins().hasPlugin('com.android.application') || |
| 145 | + project.getPlugins().hasPlugin('com.android.library')) { |
| 146 | + archives androidSourcesJar |
| 147 | + archives androidJavadocsJar |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + android.libraryVariants.all { variant -> |
| 152 | + tasks.androidJavadocs.doFirst { |
| 153 | + classpath += files(variant.javaCompileProvider.get().classpath.files.join(File.pathSeparator)) |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + publishing.publications.all { publication -> |
| 158 | + publication.groupId = GROUP |
| 159 | + publication.version = VERSION_NAME |
| 160 | + |
| 161 | + publication.artifact androidSourcesJar |
| 162 | + publication.artifact androidJavadocsJar |
| 163 | + |
| 164 | + configurePom(publication.pom) |
| 165 | + } |
| 166 | + |
| 167 | + signing { |
| 168 | + publishing.publications.all { publication -> |
| 169 | + sign publication |
| 170 | + } |
| 171 | + } |
| 172 | +} |
0 commit comments