-
-
Save kishannareshpal/2c3e3ac25c23d23f363bcb2edf94e3f2 to your computer and use it in GitHub Desktop.
Gradle script for publishing Android Kotlin libraries to a Bintray repository using maven-publish plugin. With dependencies (also handling transitive: false and custom exclude rules), including sources and javadoc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| apply plugin: 'maven-publish' | |
| task androidJavadocs(type: Javadoc) { | |
| source = android.sourceSets.main.java.srcDirs | |
| classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) | |
| } | |
| task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { | |
| classifier = 'javadoc' | |
| from androidJavadocs.destinationDir | |
| } | |
| task androidSourcesJar(type: Jar) { | |
| classifier = 'sources' | |
| from android.sourceSets.main.java.srcDirs | |
| } | |
| publishing { | |
| publications { | |
| maven(MavenPublication) { | |
| groupId 'com.example' | |
| artifactId 'custom-artifact' | |
| version '1.0' | |
| // Or use same version as in android branch | |
| // version = android.defaultConfig.versionName | |
| artifact bundleRelease | |
| artifact androidJavadocsJar | |
| artifact androidSourcesJar | |
| pom.withXml { | |
| def dependenciesNode = asNode().appendNode('dependencies') | |
| def dependencies = [] | |
| // List all "compile" dependencies (for old Gradle) | |
| dependencies.addAll(configurations.compile.getAllDependencies()) | |
| // List all "api" dependencies (for new Gradle) | |
| dependencies.addAll(configurations.api.getAllDependencies()) | |
| // Write dependencies to POM | |
| dependencies.each { Dependency dep -> | |
| if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified") | |
| return // ignore invalid dependencies | |
| def dependencyNode = dependenciesNode.appendNode('dependency') | |
| dependencyNode.appendNode('groupId', dep.group) | |
| dependencyNode.appendNode('artifactId', dep.name) | |
| dependencyNode.appendNode('version', dep.version) | |
| if (!dep.transitive) { | |
| // If this dependency is transitive, we should force exclude all its dependencies them from the POM | |
| def exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion') | |
| exclusionNode.appendNode('groupId', '*') | |
| exclusionNode.appendNode('artifactId', '*') | |
| } else if (!dep.properties.excludeRules.empty) { | |
| // Otherwise add specified exclude rules | |
| def exclusionsNode = dependencyNode.appendNode('exclusions') | |
| dep.properties.excludeRules.each { ExcludeRule rule -> | |
| def exclusionNode = exclusionsNode.appendNode('exclusion') | |
| exclusionNode.appendNode('groupId', rule.group ?: '*') | |
| exclusionNode.appendNode('artifactId', rule.module ?: '*') | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment