Created
June 6, 2018 06:17
-
-
Save act262/e1f12b52f87112057921cff755ac1c72 to your computer and use it in GitHub Desktop.
Android aar publish to maven
This file contains 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)) | |
android.libraryVariants.all { variant -> | |
if (variant.name == 'release') { | |
owner.classpath += variant.javaCompile.classpath | |
} | |
} | |
exclude '**/R.html', '**/R.*.html', '**/index.html' | |
} | |
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 'cz.example' | |
//artifactId 'custom-artifact' | |
//version = android.defaultConfig.versionName | |
artifact bundleRelease | |
artifact androidJavadocsJar | |
artifact androidSourcesJar | |
pom.withXml { | |
final dependenciesNode = asNode().appendNode('dependencies') | |
ext.addDependency = { Dependency dep, String scope -> | |
if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified") | |
return // ignore invalid dependencies | |
final dependencyNode = dependenciesNode.appendNode('dependency') | |
dependencyNode.appendNode('groupId', dep.group) | |
dependencyNode.appendNode('artifactId', dep.name) | |
dependencyNode.appendNode('version', dep.version) | |
dependencyNode.appendNode('scope', scope) | |
if (!dep.transitive) { | |
// If this dependency is transitive, we should force exclude all its dependencies them from the POM | |
final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion') | |
exclusionNode.appendNode('groupId', '*') | |
exclusionNode.appendNode('artifactId', '*') | |
} else if (!dep.properties.excludeRules.empty) { | |
// Otherwise add specified exclude rules | |
final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion') | |
dep.properties.excludeRules.each { ExcludeRule rule -> | |
exclusionNode.appendNode('groupId', rule.group ?: '*') | |
exclusionNode.appendNode('artifactId', rule.module ?: '*') | |
} | |
} | |
} | |
// List all "compile" dependencies (for old Gradle) | |
configurations.compile.getAllDependencies().each { dep -> addDependency(dep, "compile") } | |
// List all "api" dependencies (for new Gradle) as "compile" dependencies | |
configurations.api.getAllDependencies().each { dep -> addDependency(dep, "compile") } | |
// List all "implementation" dependencies (for new Gradle) as "runtime" dependencies | |
configurations.implementation.getAllDependencies().each { dep -> addDependency(dep, "runtime") } | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment