Created
April 3, 2018 22:40
-
-
Save warnyul/8bcacfc2dd96094170a86369ae4b9fba to your computer and use it in GitHub Desktop.
Write version to pom, when version is resolved from BOM
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: '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