Skip to content

Instantly share code, notes, and snippets.

@JakeWharton
Last active February 7, 2023 10:49
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JakeWharton/2066f5e4f08fbaaa68fd to your computer and use it in GitHub Desktop.
Save JakeWharton/2066f5e4f08fbaaa68fd to your computer and use it in GitHub Desktop.
Prevent wildcard versions in your Gradle project. These undermine deterministic and hermetic builds and are generally considered bad practice.
allprojects {
afterEvaluate { project ->
project.configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.version.contains('+')) {
throw new GradleException("Wildcard dependency forbidden: ${requested.group}:${requested.name}:${requested.version}")
}
}
}
}
}
@plastiv
Copy link

plastiv commented Jul 23, 2015

Shouldn't it be details.target instead of details.requested?

If I have a dependency and it's author have used '+', then I can't change it's sources and your script would abort my build. But I can use resolutionStrategy.force "group:name:exact_version" to make sure that my build uses exact version of the transitive dependency even if it's author doesn't mean it so.

@JakeWharton
Copy link
Author

@plastiv Good point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment