Skip to content

Commit

Permalink
handle properties version lookup in grails-bom (#13948)
Browse files Browse the repository at this point in the history
* handle properties version lookup in grails-bom

* PR feedback
  • Loading branch information
jamesfredley authored Dec 31, 2024
1 parent 7d706cc commit 5860c82
Showing 1 changed file with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014 original authors
* Copyright 2014-2024 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -68,10 +68,37 @@ 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) {
version?.startsWith('${') && version?.endsWith('}') ?
versionProperties[version[2..-2]] : version
}

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

0 comments on commit 5860c82

Please sign in to comment.