-
-
Save KondaReddyR/dc73cb8f6c00530bbcf8 to your computer and use it in GitHub Desktop.
Gradle file to enforce Semantic Versioning.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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