Skip to content

Commit

Permalink
handle properties version lookup in grails-bom
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesfredley committed Dec 31, 2024
1 parent 7d706cc commit ad55de9
Showing 1 changed file with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,40 @@ class GrailsDependencyVersions implements DependencyManagement {

@CompileDynamic
void addDependencyManagement(GPathResult pom) {
versionProperties = pom.properties.'*'.collectEntries { [(it.name()): it.text()] }
pom.dependencyManagement.dependencies.dependency.each { dep ->
addDependency(dep.groupId.text(), dep.artifactId.text(), dep.version.text())
addDependency(dep.groupId.text(), dep.artifactId.text(), versionLookup(dep.version.text()))
}
versionProperties = pom.properties.'*'.collectEntries { [(it.name()): it.text()] }
}

/**
* Handles properties version lookup in grails-bom
*
* <properties>
* <ant.version>1.10.15</ant.version>
* </properties>
*
* <dependencyManagement>
* <dependencies>
* <dependency>
* <groupId>org.apache.ant</groupId>
* <artifactId>ant</artifactId>
* <version>${ant.version}</version>
* </dependency>
* </dependencies>
* </dependencyManagement>
*
* @param version
* either the version or the version to lookup
*
* @return the version with lookup from properties when required
*/
String versionLookup(String version){
if (version?.startsWith('${') && version?.endsWith('}')) {
return versionProperties.get(version.substring(2, version.length()-1))
}

return version
}

protected void addDependency(String group, String artifactId, String version) {
Expand Down

0 comments on commit ad55de9

Please sign in to comment.