|
| 1 | +import com.novoda.gradle.release.Artifacts |
| 2 | +import com.novoda.gradle.release.JavaArtifacts |
| 3 | +import org.gradle.api.capabilities.Capability |
| 4 | +import org.gradle.api.internal.DefaultDomainObjectSet |
| 5 | +import org.gradle.api.internal.component.SoftwareComponentInternal |
| 6 | +import org.gradle.api.internal.component.UsageContext |
| 7 | + |
1 | 8 | /* |
2 | 9 | * Copyright 2017 Appmattus Limited |
3 | 10 | * |
|
14 | 21 | * limitations under the License. |
15 | 22 | */ |
16 | 23 |
|
17 | | -apply plugin: 'com.novoda.bintray-release' |
| 24 | +buildscript { |
| 25 | + repositories { |
| 26 | + google() |
| 27 | + jcenter() |
| 28 | + maven { url "https://plugins.gradle.org/m2/" } |
| 29 | + maven { url "https://kotlin.bintray.com/kotlinx" } |
| 30 | + } |
| 31 | + |
| 32 | + dependencies { |
| 33 | + classpath 'com.novoda:bintray-release:0.8.1' |
| 34 | + } |
| 35 | +} |
| 36 | + |
18 | 37 |
|
19 | | -publish { |
20 | | - bintrayUser = System.getenv('BINTRAY_USER') ?: System.getProperty('BINTRAY_USER') ?: "unknown" |
21 | | - bintrayKey = System.getenv('BINTRAY_KEY') ?: System.getProperty('BINTRAY_KEY') ?: "unknown" |
| 38 | +apply plugin: 'com.jfrog.bintray' |
| 39 | +apply plugin: 'maven-publish' |
22 | 40 |
|
23 | | - userOrg = 'appmattus' |
24 | | - groupId = 'com.appmattus' |
25 | | - artifactId = project.name |
26 | | - publishVersion = System.getenv('CIRCLE_TAG') ?: System.getProperty('CIRCLE_TAG') ?: System.getenv('TRAVIS_TAG') ?: |
27 | | - System.getProperty('TRAVIS_TAG') ?: "unknown" |
28 | | - desc = 'Caching made simple for Android and Java' |
29 | | - website = 'https://github.com/appmattus/layercache' |
| 41 | +ext.publishVersion = System.getenv('CIRCLE_TAG') ?: System.getProperty('CIRCLE_TAG') ?: System.getenv('TRAVIS_TAG') ?: |
| 42 | + System.getProperty('TRAVIS_TAG') ?: "unknown" |
| 43 | +ext.projectGroupId = 'com.appmattus' |
30 | 44 |
|
| 45 | +bintray { |
| 46 | + user = System.getenv('BINTRAY_USER') ?: System.getProperty('BINTRAY_USER') ?: "unknown" |
| 47 | + key = System.getenv('BINTRAY_KEY') ?: System.getProperty('BINTRAY_KEY') ?: "unknown" |
| 48 | + publish = true |
31 | 49 | dryRun = false |
| 50 | + override = false |
| 51 | + |
| 52 | + publications = project.plugins.hasPlugin('com.android.library') ? ['release'] : ['maven'] |
| 53 | + |
| 54 | + pkg { |
| 55 | + repo = 'maven' |
| 56 | + userOrg = 'appmattus' |
| 57 | + name = project.name |
| 58 | + desc = 'Caching made simple for Android and Java' |
| 59 | + websiteUrl = 'https://github.com/appmattus/layercache' |
| 60 | + issueTrackerUrl = 'https://github.com/appmattus/layercache/issues' |
| 61 | + vcsUrl = 'https://github.com/appmattus/layercache.git' |
| 62 | + |
| 63 | + licenses = ['Apache-2.0'] |
| 64 | + version { |
| 65 | + name = publishVersion |
| 66 | + attributes = [:] |
| 67 | + } |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +// Portions below modified from https://github.com/novoda/bintray-release |
| 72 | +// Copyright 2014 Novoda Ltd |
| 73 | +// Apache 2.0 Licence |
| 74 | + |
| 75 | +if (project.plugins.hasPlugin('com.android.library')) { |
| 76 | + project.android.libraryVariants.all { variant -> |
| 77 | + def artifactId = project.name; |
| 78 | + addArtifact(project, variant.name, artifactId, new AndroidArtifactsAppmattus(variant)) |
| 79 | + } |
| 80 | +} else { |
| 81 | + addArtifact(project, 'maven', project.name, new JavaArtifacts()) |
| 82 | +} |
| 83 | + |
| 84 | +void addArtifact(Project project, String name, String artifact, Artifacts artifacts) { |
| 85 | + project.publishing.publications.create(name, MavenPublication) { |
| 86 | + groupId projectGroupId |
| 87 | + artifactId artifact |
| 88 | + version = publishVersion |
| 89 | + |
| 90 | + artifacts.all(it.name, project).each { |
| 91 | + delegate.artifact it |
| 92 | + } |
| 93 | + from artifacts.from(project) |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +class AndroidArtifactsAppmattus implements Artifacts { |
| 98 | + |
| 99 | + def variant |
| 100 | + |
| 101 | + AndroidArtifactsAppmattus(variant) { |
| 102 | + this.variant = variant |
| 103 | + } |
| 104 | + |
| 105 | + def all(String publicationName, Project project) { |
| 106 | + [sourcesJar(project), javadocJar(project), mainJar(project)] |
| 107 | + } |
| 108 | + |
| 109 | + def sourcesJar(Project project) { |
| 110 | + project.task(variant.name + 'AndroidSourcesJar', type: Jar) { |
| 111 | + classifier = 'sources' |
| 112 | + variant.sourceSets.each { |
| 113 | + from it.java.srcDirs |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + def javadocJar(Project project) { |
| 119 | + def androidJavadocs = project.task(variant.name + 'AndroidJavadocs', type: Javadoc) { |
| 120 | + variant.sourceSets.each { |
| 121 | + delegate.source it.java.srcDirs |
| 122 | + } |
| 123 | + classpath += project.files(project.android.getBootClasspath().join(File.pathSeparator)) |
| 124 | + classpath += variant.javaCompile.classpath |
| 125 | + classpath += variant.javaCompile.outputs.files |
| 126 | + } |
| 127 | + |
| 128 | + project.task(variant.name + 'AndroidJavadocsJar', type: Jar, dependsOn: androidJavadocs) { |
| 129 | + classifier = 'javadoc' |
| 130 | + from androidJavadocs.destinationDir |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + def mainJar(Project project) { |
| 135 | + def archiveBaseName = project.hasProperty("archivesBaseName") ? project.getProperty("archivesBaseName") : project.name |
| 136 | + "$project.buildDir/outputs/aar/$archiveBaseName-${variant.baseName}.aar" |
| 137 | + } |
| 138 | + |
| 139 | + def from(Project project) { |
| 140 | + project.components.add(new AndroidLibraryAppmattus(project)) |
| 141 | + project.components.android |
| 142 | + } |
| 143 | +} |
| 144 | + |
| 145 | + |
| 146 | +class AndroidLibraryAppmattus implements SoftwareComponentInternal { |
| 147 | + |
| 148 | + private final String CONF_COMPILE = "compile" |
| 149 | + private final String CONF_API = "api" |
| 150 | + private final String CONF_IMPLEMENTATION = "implementation" |
| 151 | + |
| 152 | + private final Set<UsageContext> usages = new DefaultDomainObjectSet<UsageContext>(UsageContext) |
| 153 | + |
| 154 | + AndroidLibraryAppmattus(Project project) { |
| 155 | + ObjectFactory objectFactory = project.getObjects() |
| 156 | + |
| 157 | + Usage api = objectFactory.named(Usage.class, Usage.JAVA_API) |
| 158 | + Usage runtime = objectFactory.named(Usage.class, Usage.JAVA_RUNTIME) |
| 159 | + |
| 160 | + addUsageContextFromConfiguration(project, CONF_COMPILE, api) |
| 161 | + addUsageContextFromConfiguration(project, CONF_API, api) |
| 162 | + addUsageContextFromConfiguration(project, CONF_IMPLEMENTATION, runtime) |
| 163 | + } |
| 164 | + |
| 165 | + String getName() { |
| 166 | + return "android" |
| 167 | + } |
| 168 | + |
| 169 | + Set<UsageContext> getUsages() { |
| 170 | + return usages |
| 171 | + } |
| 172 | + |
| 173 | + private addUsageContextFromConfiguration(Project project, String configuration, Usage usage) { |
| 174 | + try { |
| 175 | + def configurationObj = project.configurations.getByName(configuration) |
| 176 | + def dependency = configurationObj.dependencies |
| 177 | + if (!dependency.isEmpty()) { |
| 178 | + def libraryUsage = new LibraryUsage(dependency, usage) |
| 179 | + usages.add(libraryUsage) |
| 180 | + } |
| 181 | + } catch (UnknownDomainObjectException ignore) { |
| 182 | + // cannot find configuration |
| 183 | + } |
| 184 | + } |
| 185 | + |
| 186 | + private static class LibraryUsage implements UsageContext { |
| 187 | + |
| 188 | + private final DomainObjectSet<Dependency> dependencies |
| 189 | + private final Usage usage |
| 190 | + |
| 191 | + LibraryUsage(DomainObjectSet<Dependency> dependencies, Usage usage) { |
| 192 | + this.usage = usage |
| 193 | + this.dependencies = dependencies |
| 194 | + } |
| 195 | + |
| 196 | + @Override |
| 197 | + Usage getUsage() { |
| 198 | + return usage |
| 199 | + } |
| 200 | + |
| 201 | + @Override |
| 202 | + Set<? extends PublishArtifact> getArtifacts() { |
| 203 | + new LinkedHashSet<PublishArtifact>() |
| 204 | + } |
| 205 | + |
| 206 | + @Override |
| 207 | + Set<? extends ModuleDependency> getDependencies() { |
| 208 | + dependencies.withType(ModuleDependency) |
| 209 | + } |
| 210 | + |
| 211 | + @Override |
| 212 | + Set<? extends DependencyConstraint> getDependencyConstraints() { |
| 213 | + return [] |
| 214 | + } |
| 215 | + |
| 216 | + @Override |
| 217 | + Set<? extends Capability> getCapabilities() { |
| 218 | + return [] |
| 219 | + } |
| 220 | + |
| 221 | + @Override |
| 222 | + Set<ExcludeRule> getGlobalExcludes() { |
| 223 | + return [] |
| 224 | + } |
| 225 | + |
| 226 | + @Override |
| 227 | + String getName() { |
| 228 | + return "runtime" |
| 229 | + } |
| 230 | + |
| 231 | + @Override |
| 232 | + AttributeContainer getAttributes() { |
| 233 | + return null |
| 234 | + } |
| 235 | + } |
32 | 236 | } |
0 commit comments