Skip to content

Instantly share code, notes, and snippets.

@warnyul
Created April 3, 2018 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warnyul/8bcacfc2dd96094170a86369ae4b9fba to your computer and use it in GitHub Desktop.
Save warnyul/8bcacfc2dd96094170a86369ae4b9fba to your computer and use it in GitHub Desktop.
Write version to pom, when version is resolved from BOM
apply plugin: 'com.android.library'
apply plugin: 'digital.wup.android-maven-publish'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
// import a BOM
implementation 'org.springframework.boot:spring-boot-dependencies:1.5.8.RELEASE'
// define dependencies without versions
implementation "com.google.code.gson:gson"
}
def getResolvedVersionOf(group, name) {
return configurations.releaseRuntimeClasspath.resolvedConfiguration.firstLevelModuleDependencies.asList().find { e ->
if (e.moduleGroup == group && e.moduleName == name) {
return e
}
}?.moduleVersion
}
publishing {
publications {
aar(MavenPublication) {
from components.android
pom.withXml {
Node pomNode = asNode()
pomNode.dependencies.first().children().each { dependencyNode ->
// version node is not found in pom
if (!dependencyNode.get('version')) {
def groupId = dependencyNode.get('groupId').text()
def artifactId = dependencyNode.get('artifactId').text()
def version = getResolvedVersionOf(groupId, artifactId)
if (version) {
// Append resolved version
dependencyNode.appendNode('version', version)
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment