Skip to content

Instantly share code, notes, and snippets.

@quidryan
Created February 15, 2013 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save quidryan/4962525 to your computer and use it in GitHub Desktop.
Save quidryan/4962525 to your computer and use it in GitHub Desktop.
Gradle file to enforce Semantic Versioning.
apply plugin: "java"
repositories {
mavenCentral()
}
dependencies {
compile "org.spockframework:spock-core:0.7-groovy-2.0"
compile "org.codehaus.groovy:groovy-all:1.8.6"
}
configurations.all {
incoming.resolutionResult.allDependencies { DependencyResult dependencyResult ->
if (!SemanticVersion.isMatch(dependencyResult.requested.version) || !SemanticVersion.isMatch(dependencyResult.selected.id.version)) {
return
}
def requested = new SemanticVersion(dependencyResult.requested.version)
def selected = new SemanticVersion(dependencyResult.selected.id.version)
if (requested.major != selected.major) {
throw new Exception("Dependency $dependencyResult has a different selected major version than was requested")
}
}
}
class SemanticVersion {
int major
int minor
int patch
SemanticVersion(String version) {
(major, minor, patch) = version.split("\\.")
}
static boolean isMatch(String version) {
version ==~ /\d+\.\d+\.\d+/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment