Skip to content

Commit

Permalink
Add another test that shows dependencies can be modified from beforeR…
Browse files Browse the repository at this point in the history
…esolve
  • Loading branch information
big-guy authored and ljacomet committed Jan 27, 2023
1 parent bd88312 commit f492a51
Showing 1 changed file with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,79 @@ import org.gradle.util.TestPrecondition
import spock.lang.Issue

class BeforeResolveIntegrationTest extends AbstractDependencyResolutionTest {
def "can use beforeResolve hook to modify add dependencies"() {
mavenRepo.module('org.test', 'dep1', '1.0').publish()
mavenRepo.module('org.test', 'dep2', '1.0').publish()
mavenRepo.module('org.test', 'dep3', '1.0').publish()

buildFile << """
repositories {
maven { url '${mavenRepo.uri}' }
}
configurations {
conf
}
dependencies {
conf 'org.test:dep1:1.0'
}
configurations.conf.incoming.beforeResolve { resolvableDependencies ->
project.dependencies.add('conf', 'org.test:dep2:1.0')
}
task printFiles {
def conf = configurations.conf
doLast {
def files = conf.collect { it.name }
println files
assert files == ['dep1-1.0.jar', 'dep2-1.0.jar']
}
}
task printFilesWithConfigurationInput {
dependsOn configurations.conf
def conf = configurations.conf
doLast {
def files = conf.collect { it.name }
println files
assert files == ['dep1-1.0.jar', 'dep2-1.0.jar']
}
}
task copyFiles(type:Copy) {
from configurations.conf
into 'libs'
}
"""

when:
succeeds 'printFiles'

then:
outputContains('[dep1-1.0.jar, dep2-1.0.jar]')

when:
succeeds 'printFilesWithConfigurationInput'

then:
outputContains('[dep1-1.0.jar, dep2-1.0.jar]')

when:
succeeds 'copyFiles'
then:
file('libs').assertHasDescendants('dep1-1.0.jar', 'dep2-1.0.jar')

when:
buildFile << """
// add another dependency to conf
configurations.conf.incoming.beforeResolve { resolvableDependencies ->
project.dependencies.add('conf', 'org.test:dep3:1.0')
}
"""
succeeds "copyFiles"
then:
file('libs').assertHasDescendants('dep1-1.0.jar', 'dep2-1.0.jar', 'dep3-1.0.jar')
}

@Issue("gradle/gradle#2480")
def "can use beforeResolve hook to modify dependency excludes"() {
Expand Down

0 comments on commit f492a51

Please sign in to comment.