Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent builds from failing w/ configuration cache enabled on Gradle 7.4+ #585

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
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
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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can simply invoke the method since it is dynamically typed? Our other usages only guard before making the method call directly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not the most well versed on Groovy because that's what I thought as well, but the IDE was showing it as red. I didn't actually try running it though.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha, me neither. I just use VSCode and pray =)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just double checked and it won't run. I'm assuming the compiler can't see it because the version of the Gradle API needs to be bumped, but not sure if that is desired at the moment.

Copy link
Owner

@ben-manes ben-manes Feb 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, thanks! (Let's keep your code as is)

}

@TaskAction
Expand Down
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',
]
}
}