Skip to content

Commit

Permalink
Merge pull request #24 from rspieldenner/respect_forces
Browse files Browse the repository at this point in the history
Fixes #20 Bugfix for respecting forces in build.gradle
  • Loading branch information
rspieldenner committed Jun 2, 2014
2 parents f1642ce + 09396db commit bc98ee0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
1.9.9 / 2014-05-xx
==================

* Bugfix: properly respect resolutionStrategy.force 'group:artifact:version' present in build.gradle
* Add commitLock task

1.9.8 / 2014-05-02
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,26 +132,31 @@ class DependencyLockPlugin implements Plugin<Project> {
logger.info("Using command line overrides ${project['dependencyLock.override']}")
}

def overrideModules = overrides.collect { "${it.key}:${it.value}" }
def overrideForces = overrides.collect { "${it.key}:${it.value}" }
logger.debug(overrideForces.toString())

project.configurations.all {
resolutionStrategy.forcedModules = overrideModules
resolutionStrategy {
overrideForces.each { dep -> force dep}
}
}
}

void applyLock(File dependenciesLock, Map overrides) {
logger.info("Using ${dependenciesLock.name} to lock dependencies")
def locks = loadLock(dependenciesLock)
def nonProjectLocks = locks.findAll { it.value?.locked }
def forcedModules = nonProjectLocks.collect {
def lockForces = nonProjectLocks.collect {
overrides.containsKey(it.key) ? "${it.key}:${overrides[it.key]}" : "${it.key}:${it.value.locked}"
}
def unusedOverrides = overrides.findAll { !locks.containsKey(it.key) }.collect { "${it.key}:${it.value}" }
forcedModules << unusedOverrides
logger.debug(forcedModules.toString())
lockForces << unusedOverrides
logger.debug(lockForces.toString())

project.configurations.all {
resolutionStrategy.forcedModules = forcedModules
resolutionStrategy {
lockForces.each { dep -> force dep}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,33 @@ class DependencyLockPluginSpec extends ProjectSpec {
foo.moduleVersion == '2.0.1'
}

def 'command line override of a dependency with forces in place'() {
stockTestSetup()

project.dependencies {
compile 'test.example:baz:1.+'
}

project.configurations.all {
resolutionStrategy {
force 'test.example:baz:1.0.0'
}
}

project.ext.set('dependencyLock.override', 'test.example:foo:2.0.1')

when:
project.apply plugin: pluginName
triggerTaskGraphWhenReady()
def resolved = project.configurations.compile.resolvedConfiguration

then:
def foo = resolved.firstLevelModuleDependencies.find { it.moduleName == 'foo' }
foo.moduleVersion == '2.0.1'
def baz = resolved.firstLevelModuleDependencies.find { it.moduleName == 'baz' }
baz.moduleVersion == '1.0.0'
}

def 'command line overrides of multiple dependencies'() {
def dependenciesLock = new File(projectDir, 'dependencies.lock')
dependenciesLock << '''\
Expand Down

0 comments on commit bc98ee0

Please sign in to comment.