Skip to content

Commit

Permalink
Merge pull request #585 from eygraber/dont-fail-w-configuration-cache
Browse files Browse the repository at this point in the history
Prevent builds from failing w/ configuration cache enabled on Gradle 7.4+
  • Loading branch information
eygraber authored Feb 4, 2022
2 parents ebd1655 + 2e75446 commit b53e44f
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {
}

group = 'com.github.ben-manes'
version = '0.41.0'
version = '0.42.0'

sourceCompatibility = JavaVersion.VERSION_1_8

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ class DependencyUpdatesTask extends DefaultTask {
group = 'Help'

outputs.upToDateWhen { false }

if(supportsIncompatibleWithConfigurationCache()) {
callIncompatibleWithConfigurationCache()
}
}

private boolean supportsIncompatibleWithConfigurationCache() {
return metaClass.respondsTo(this, "notCompatibleWithConfigurationCache", String)
}

private void callIncompatibleWithConfigurationCache() {
String methodName = "notCompatibleWithConfigurationCache"
Object[] methodArgs = ["The gradle-versions-plugin isn't compatible with the configuration cache"]
metaClass.invokeMethod(this, methodName, methodArgs)
}

@TaskAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,124 @@ final class DifferentGradleVersionsSpec extends Specification {
result.output.contains('com.google.inject:guice [3.0 -> 3.1]')
srdErrWriter.toString().empty
}

def 'dependencyUpdates task completes without errors if configuration cache is enabled with Gradle 7.4'() {
given:
def srdErrWriter = new StringWriter()

buildFile = testProjectDir.newFile('build.gradle')
buildFile <<
"""
buildscript {
dependencies {
classpath files($classpathString)
}
}
apply plugin: 'java'
apply plugin: "com.github.ben-manes.versions"
repositories {
maven {
url '${mavenRepoUrl}'
}
}
dependencies {
implementation 'com.google.inject:guice:3.0'
}
""".stripIndent()

testProjectDir.newFolder("gradle")

when:
def result = GradleRunner.create()
.withGradleVersion('7.4-rc-2')
.withProjectDir(testProjectDir.root)
.withArguments('dependencyUpdates', '--configuration-cache')
.forwardStdError(srdErrWriter)
.build()

then:
result.output.contains('BUILD SUCCESSFUL')
srdErrWriter.toString().empty
}

@Unroll
def 'dependencyUpdates task fails if configuration cache is enabled with Gradle #gradleVersion'() {
given:
buildFile = testProjectDir.newFile('build.gradle')
buildFile <<
"""
buildscript {
dependencies {
classpath files($classpathString)
}
}
apply plugin: 'java'
apply plugin: "com.github.ben-manes.versions"
// Gradle 7.0+ do not allow directly using compile configuration so we monkey patch
// an implementation configuration in for older Gradle versions.
if (configurations.findByName('implementation') == null) {
configurations.create('implementation') {
extendsFrom configurations.compile
}
}
repositories {
maven {
url '${mavenRepoUrl}'
}
}
dependencies {
implementation 'com.google.inject:guice:2.0'
}
""".stripIndent()

when:
def arguments = ['dependencyUpdates']
// Warning mode reporting only supported on recent versions.
if (gradleVersion.substring(0, gradleVersion.indexOf('.')).toInteger() >= 6) {
arguments.add('--warning-mode=fail')
}
arguments.add('-S')
arguments.add('--configuration-cache')
def result = GradleRunner.create()
.withGradleVersion(gradleVersion)
.withProjectDir(testProjectDir.root)
.withArguments(arguments)
.buildAndFail()

then:
result.output.contains('FAILURE: Build failed with an exception.')
result.output.contains('Configuration cache problems found in this build.')

where:
gradleVersion << [
'6.6',
'6.6.1',
'6.7',
'6.7.1',
'6.8',
'6.8.1',
'6.8.2',
'6.8.3',
'6.9',
'6.9.1',
'6.9.2',
'7.0',
'7.0.1',
'7.0.2',
'7.1',
'7.1.1',
'7.2',
'7.3',
'7.3.1',
'7.3.2',
'7.3.3',
]
}
}

0 comments on commit b53e44f

Please sign in to comment.