|
| 1 | +import de.mannodermaus.gradle.plugins.junit5.Artifacts |
| 2 | + |
| 3 | +// Common logic shared across modules whose artifacts are provided to jCenter and Sonatype OSS. |
| 4 | +// |
| 5 | +// This script expects an extra named "deployConfig" to exist on the Project instance. |
| 6 | +// Its type is defined within the buildSrc module of this project. |
| 7 | + |
| 8 | +/** Obtains a required parameter from a Map, or throws an Exception if it's absent */ |
| 9 | +private def required(Map config, String property) { |
| 10 | + def value = config.get(property, null) |
| 11 | + if (!value) { |
| 12 | + throw new IllegalStateException( |
| 13 | + "Deployment for module '$name' is missing required parameter '$property'") |
| 14 | + } |
| 15 | + return value |
| 16 | +} |
| 17 | + |
| 18 | +// Access Map properties |
| 19 | +if (!project.ext.has("deployConfig")) { |
| 20 | + throw new IllegalStateException("Deployed module '$name' requires a 'deployConfig'") |
| 21 | +} |
| 22 | + |
| 23 | +final de.mannodermaus.gradle.plugins.junit5.Artifact deployConfig = project.ext.deployConfig |
| 24 | +final String targetPlatform = deployConfig.platform.name |
| 25 | +final String groupId = deployConfig.groupId |
| 26 | +final String artifactId = deployConfig.artifactId |
| 27 | +final String versionNumber = deployConfig.currentVersion |
| 28 | +final String license = deployConfig.license |
| 29 | +final String description = deployConfig.description |
| 30 | + |
| 31 | +// Apply required plugins |
| 32 | +apply plugin: "com.jfrog.bintray" |
| 33 | + |
| 34 | +if (targetPlatform == "java") { |
| 35 | + // Releases |
| 36 | + apply plugin: "maven" |
| 37 | + // Snapshots |
| 38 | + apply plugin: "maven-publish" |
| 39 | +} else if (targetPlatform == "android") { |
| 40 | + // Releases |
| 41 | + apply plugin: "com.github.dcendents.android-maven" |
| 42 | + // Snapshots |
| 43 | + apply plugin: "digital.wup.android-maven-publish" |
| 44 | +} |
| 45 | + |
| 46 | +// ------------------------------------------------------------------------------------------------ |
| 47 | +// Artifacts Configuration |
| 48 | +// ------------------------------------------------------------------------------------------------ |
| 49 | + |
| 50 | +// Include sources.jar archive in each release |
| 51 | +if (targetPlatform == "java") { |
| 52 | + task sourcesJar(type: Jar, dependsOn: classes) { |
| 53 | + baseName = artifactId |
| 54 | + classifier = "sources" |
| 55 | + from sourceSets.main.allSource |
| 56 | + } |
| 57 | +} else { |
| 58 | + task sourcesJar(type: Jar) { |
| 59 | + baseName = artifactId |
| 60 | + classifier = "sources" |
| 61 | + from android.sourceSets.main.java.srcDirs |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +// Include javadoc.jar archive in each release |
| 66 | +if (targetPlatform == "android") { |
| 67 | + task javadoc(type: Javadoc) { |
| 68 | + source = android.sourceSets.main.java.srcDirs |
| 69 | + excludes = ["**/*.kt"] |
| 70 | + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +task javadocJar(type: Jar, dependsOn: javadoc) { |
| 75 | + baseName = artifactId |
| 76 | + classifier = "javadoc" |
| 77 | + from javadoc.destinationDir |
| 78 | +} |
| 79 | + |
| 80 | +// ------------------------------------------------------------------------------------------------ |
| 81 | +// Publication Configuration |
| 82 | +// ------------------------------------------------------------------------------------------------ |
| 83 | + |
| 84 | +group = groupId |
| 85 | +archivesBaseName = artifactId |
| 86 | +version = versionNumber |
| 87 | + |
| 88 | +publishing { |
| 89 | + publications { |
| 90 | + library(MavenPublication) { p -> |
| 91 | + p.from components.getByName(targetPlatform) |
| 92 | + p.artifact sourcesJar |
| 93 | + p.artifact javadocJar |
| 94 | + p.groupId groupId |
| 95 | + p.artifactId artifactId |
| 96 | + p.version version |
| 97 | + p.pom.withXml { |
| 98 | + def root = asNode() |
| 99 | + root.appendNode("description", description) |
| 100 | + root.appendNode("name", artifactId) |
| 101 | + root.appendNode("url", Artifacts.githubUrl) |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +// Copy POM to location expected by Bintray |
| 108 | +task copyPom(type: Copy) { |
| 109 | + from "build/publications/library" |
| 110 | + into "build/poms" |
| 111 | + include "pom-default.xml" |
| 112 | +} |
| 113 | + |
| 114 | +publish.dependsOn copyPom |
| 115 | + |
| 116 | +// ------------------------------------------------------------------------------------------------ |
| 117 | +// Target Configuration |
| 118 | +// ------------------------------------------------------------------------------------------------ |
| 119 | + |
| 120 | +project.configure(project) { |
| 121 | + if (project.version.endsWith("-SNAPSHOT")) { |
| 122 | + // Configure deployment of snapshot versions to Sonatype OSS |
| 123 | + project.publishing { |
| 124 | + repositories { |
| 125 | + maven { |
| 126 | + name "snapshot" |
| 127 | + credentials { |
| 128 | + username project.ext["deployment.sonatypeUser"] |
| 129 | + password project.ext["deployment.sonatypePass"] |
| 130 | + } |
| 131 | + url "https://oss.sonatype.org/content/repositories/snapshots" |
| 132 | + } |
| 133 | + } |
| 134 | + } |
| 135 | + project.tasks.getByName("bintrayUpload").enabled = false |
| 136 | + |
| 137 | + } else { |
| 138 | + // Configure deployment of release versions to Bintray |
| 139 | + project.artifacts { |
| 140 | + archives javadocJar |
| 141 | + archives sourcesJar |
| 142 | + } |
| 143 | + |
| 144 | + project.bintray { |
| 145 | + user = project.ext["deployment.bintrayUser"] |
| 146 | + key = project.ext["deployment.bintrayKey"] |
| 147 | + configurations = ["archives"] |
| 148 | + dryRun = false |
| 149 | + publish = true |
| 150 | + pkg { |
| 151 | + repo = "maven" |
| 152 | + name = artifactId |
| 153 | + desc = description |
| 154 | + licenses = [license] |
| 155 | + githubRepo = Artifacts.githubRepo |
| 156 | + websiteUrl = Artifacts.githubUrl |
| 157 | + vcsUrl = "${Artifacts.githubUrl}.git" |
| 158 | + issueTrackerUrl = "${Artifacts.githubUrl}/issues" |
| 159 | + publicDownloadNumbers = true |
| 160 | + version { |
| 161 | + name = versionNumber |
| 162 | + desc = description |
| 163 | + } |
| 164 | + } |
| 165 | + } |
| 166 | + } |
| 167 | +} |
0 commit comments