Skip to content

Instantly share code, notes, and snippets.

@calid
Last active November 3, 2015 15:04
Show Gist options
  • Save calid/751bef0dd3c59307f368 to your computer and use it in GitHub Desktop.
Save calid/751bef0dd3c59307f368 to your computer and use it in GitHub Desktop.
Manually substitute '+' version specifier in Gradle generated pom
uploadArchives {
repositories {
mavenDeployer {
repository url: 'file:///tmp/testRepo'
pom.whenConfigured { p ->
// get all unresolved dependencies in our pom
def unresolved = p.getDependencies()
.grep { it.version == '+' }
for (u in unresolved) {
def artifact =
"${u.groupId}:${u.artifactId}:${u.version}"
// crawl each configuration and try to find a resolution
// result for our unresolved artifact
def resolved
for ( c in project.configurations) {
def deps = c.incoming
.getResolutionResult()
.getAllDependencies()
// a matching resolution result will have a requested
// artifact name identical to our unresolved artifact
resolved =
deps.grep { "${it.getRequested()}" == artifact }
.getAt(0)
if (resolved) {
break
}
}
if (resolved) {
// now replace the unresolved version with the
// version selected by the resolution result
u.version = resolved.getSelected()
.getModuleVersion()
.getVersion()
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment