|
| 1 | +if (versions == null || versions.publish_version == null) { |
| 2 | + throw new IllegalStateException("Unable to reference publish_version!") |
| 3 | +} else if (module_group == null || module_name == null) { |
| 4 | + throw new IllegalStateException("Must provide module_group and module_name!") |
| 5 | +} |
| 6 | + |
| 7 | +apply plugin: 'maven-publish' |
| 8 | +apply plugin: 'signing' |
| 9 | + |
| 10 | +task androidSourcesJar(type: Jar) { |
| 11 | + archiveClassifier.set('sources') |
| 12 | + if (project.plugins.findPlugin("com.android.library")) { |
| 13 | + // For Android libraries |
| 14 | + from android.sourceSets.main.java.srcDirs |
| 15 | + from android.sourceSets.main.kotlin.srcDirs |
| 16 | + } else { |
| 17 | + // For pure Kotlin libraries, in case you have them |
| 18 | + from sourceSets.main.java.srcDirs |
| 19 | + from sourceSets.main.kotlin.srcDirs |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +artifacts { |
| 24 | + archives androidSourcesJar |
| 25 | +} |
| 26 | + |
| 27 | +group = module_group |
| 28 | +version = versions.publish_version |
| 29 | + |
| 30 | +// Default values |
| 31 | +ext["signing.keyId"] = '' |
| 32 | +ext["signing.password"] = '' |
| 33 | +ext["signing.secretKeyRingFile"] = '' |
| 34 | +ext["ossrhUsername"] = '' |
| 35 | +ext["ossrhPassword"] = '' |
| 36 | +ext["sonatypeStagingProfileId"] = '' |
| 37 | + |
| 38 | +File secretPropsFile = project.rootProject.file('local.properties') |
| 39 | +if (secretPropsFile.exists()) { |
| 40 | + Properties p = new Properties() |
| 41 | + new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) } |
| 42 | + p.each { name, value -> ext[name] = value } |
| 43 | +} else { |
| 44 | + ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID') |
| 45 | + ext["signing.password"] = System.getenv('SIGNING_PASSWORD') |
| 46 | + ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE') |
| 47 | + ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME') |
| 48 | + ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD') |
| 49 | + ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID') |
| 50 | +} |
| 51 | + |
| 52 | +publishing { |
| 53 | + publications { |
| 54 | + release(MavenPublication) { |
| 55 | + // The coordinates of the library, being set from variables that |
| 56 | + // we'll set up later |
| 57 | + groupId module_group |
| 58 | + artifactId module_name |
| 59 | + version versions.publish_version |
| 60 | + |
| 61 | + // Two artifacts, the `aar` (or `jar`) and the sources |
| 62 | + if (project.plugins.findPlugin("com.android.library")) { |
| 63 | + artifact("$buildDir/outputs/aar/${project.getName()}-release.aar") |
| 64 | + } else { |
| 65 | + artifact("$buildDir/libs/${project.getName()}-${version}.jar") |
| 66 | + } |
| 67 | + artifact androidSourcesJar |
| 68 | + |
| 69 | + // Mostly self-explanatory metadata |
| 70 | + pom { |
| 71 | + packaging 'aar' |
| 72 | + name = module_name |
| 73 | + description = '😍 A beautiful, fluid, and extensible dialogs API for Kotlin & Android.' |
| 74 | + url = 'https://github.com/afollestad/material-dialogs' |
| 75 | + licenses { |
| 76 | + license { |
| 77 | + name = 'Apache 2.0 License' |
| 78 | + url = 'https://github.com/afollestad/material-dialogs/blob/main/LICENSE.md' |
| 79 | + } |
| 80 | + } |
| 81 | + developers { |
| 82 | + developer { |
| 83 | + id = 'afollestad' |
| 84 | + name = 'Aidan Follestad' |
| 85 | + |
| 86 | + } |
| 87 | + // Add all other devs here... |
| 88 | + } |
| 89 | + // Version control info - if you're using GitHub, follow the format as seen here |
| 90 | + scm { |
| 91 | + connection = 'scm:git:github.com/afollestad/material-dialogs.git' |
| 92 | + developerConnection = 'scm:git:ssh://github.com/afollestad/material-dialogs.git' |
| 93 | + url = 'https://github.com/afollestad/material-dialogs/tree/main' |
| 94 | + } |
| 95 | + // A slightly hacky fix so that your POM will include any transitive dependencies |
| 96 | + // that your library builds upon |
| 97 | + withXml { |
| 98 | + def dependenciesNode = asNode().appendNode('dependencies') |
| 99 | + project.configurations.implementation.allDependencies.each { |
| 100 | + def dependencyNode = dependenciesNode.appendNode('dependency') |
| 101 | + dependencyNode.appendNode('groupId', it.group) |
| 102 | + dependencyNode.appendNode('artifactId', it.name) |
| 103 | + dependencyNode.appendNode('version', it.version) |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | + // The repository to publish to, Sonatype/MavenCentral |
| 110 | + repositories { |
| 111 | + maven { |
| 112 | + // This is an arbitrary name, you may also use "mavencentral" or |
| 113 | + // any other name that's descriptive for you |
| 114 | + name = "sonatype" |
| 115 | + url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" |
| 116 | + credentials { |
| 117 | + username ossrhUsername |
| 118 | + password ossrhPassword |
| 119 | + } |
| 120 | + } |
| 121 | + } |
| 122 | +} |
| 123 | + |
| 124 | +signing { |
| 125 | + sign publishing.publications |
| 126 | +} |
| 127 | + |
| 128 | +afterEvaluate { |
| 129 | + publishReleasePublicationToSonatypeRepository.dependsOn assembleRelease |
| 130 | +} |
0 commit comments