Reputation: 37974
I am using Gradle 4.6 which allows me to run build scans using the
--scan
option without having to explicitly apply or download extra plugins which is great. However this forces me to add thebuildScan
Terms of Service acceptance in my build.gradle file.
like this:
buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
}
When I subsequently run
gradle build
without the--scan
option I get the following error message:> Could not find method buildScan() for arguments…
I don’t want to have to modify the build.gradle file every time I want/dont want a scan. I don’t want to apply the plugin explicitly (firewall issues) and I don’t get the chance to accept the of Terms of Service on the command line which I have also seen documented.
Can anyone tell me what I am doing wrong?
This question is formatted like a quote because it was already asked on Gradle Forums. But it's left without answer. I'm using Gradle 4.10.2 and the problem is still actual. I decided to draw more attention to this problem here.
Upvotes: 19
Views: 17794
Reputation: 74
You can pipe "yes" as the answer using the echo
command
For example,
echo "yes" | ./gradlew build --scan
Upvotes: 3
Reputation: 16833
Just test the existence of buildScan
if (hasProperty('buildScan')) {
buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
}
}
The same can be done in a kotlin build file like this - (with thanks to this answer):
if (hasProperty("buildScan")) {
extensions.findByName("buildScan")?.withGroovyBuilder {
setProperty("termsOfServiceUrl", "https://gradle.com/terms-of-service")
setProperty("termsOfServiceAgree", "yes")
}
}
Please see Connecting to scans.gradle.com documentation for more detail.
Upvotes: 41
Reputation: 1699
This might not be a good or proper solution, but here's one workaround: use a try
/catch
to swallow the error, something like:
try {
buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
}
} catch (MissingMethodException e){
// This isn't the exception you're looking for
}
Upvotes: 0