Skip to content

Commit

Permalink
Merge pull request #11 from xebialabs/gh-10
Browse files Browse the repository at this point in the history
GH-10 Allow override of versions with extraProperties values and add a flag to disable dependency management
  • Loading branch information
ilx authored Nov 9, 2022
2 parents b38596d + fb51b26 commit a62b0bc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ class DependencyManagementContainer {
private Project rootProject = null
private boolean resolved = false

boolean manageDependencies = true

Map versions = [:].withDefault { "" }

Map<String, String> resolveCache = [:].withDefault { String s -> s ? engine.createTemplate(s).make(versions).toString() : s }
Map<String, String> resolveCache = [:].withDefault { String s ->
Map resolutionContextMap = (versions + rootProject.extensions.extraProperties.properties).withDefault { "" }
s ? engine.createTemplate(s).make(resolutionContextMap).toString() : s
}
Map managedVersions = [:]
List<GroupArtifact> blackList = []
Map rewrites = [:]
Expand Down Expand Up @@ -48,10 +53,25 @@ class DependencyManagementContainer {
}

private def exposeVersions() {
versions.collect { k, v ->
if (v !== "" && k != "out") {
logger.debug("${rootProject.name} added $k=$v")
rootProject.extensions.extraProperties.set(k, v)
versions << versions.collectEntries { k, v ->
if (k !== "out") {
if (rootProject.extensions.extraProperties.has(k)) {
def overrideValue = rootProject.extensions.extraProperties.get(k)
logger.info("${rootProject.name} added overriden version ${k}=${overrideValue} (found in gradle extra properties)")
rootProject.extensions.extraProperties.set(k, overrideValue)
[k:overrideValue]
} else {
if (v !== "") {
logger.info("${rootProject.name} added version $k=$v")
rootProject.extensions.extraProperties.set(k, v)
[k:v]
} else {
logger.error("Unable to expose version ${k} to gradle extra properties. Check if it is defined in gradle.properties or .conf file")
[k:""]
}
}
} else {
[:]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ class DependencyManagementExtension {
project.logger.info("Added dependency management artifact: $s")
container.addSupplier(new DependencySupplier(this.project, s))
}

def manageDependencies(Boolean manageDependencies) {
project.logger.info("Dependencies managed by Dependency management plugin: $manageDependencies")
container.manageDependencies = manageDependencies
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ class DependencyManagementProjectConfigurer {
// Contract for all is that it executes the closure for all currently assigned objects, and any objects added later.
project.getConfigurations().all { Configuration config ->
if (config.name != 'zinc') { // The Scala compiler 'zinc' configuration should not be managed by us
config.resolutionStrategy { ResolutionStrategy rs ->
rs.eachDependency(manageDependency(project, container))
if (container.manageDependencies) {
config.resolutionStrategy { ResolutionStrategy rs ->
rs.eachDependency(manageDependency(project, container))
}
}
configureExcludes(project, config, container)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class XLDependencyPlatformPlugin implements Plugin<Project> {
}
project.logger.info("Added $artifactModule:$artifactVersion to ${projectName}")
} else {
project.logger.info("Unable to add $artifactModule to ${projectName}")
project.logger.info("Unable to add $artifactModule to ${projectName} as a constraint")
}
}
}
Expand Down

0 comments on commit a62b0bc

Please sign in to comment.