Skip to content

Instantly share code, notes, and snippets.

@quidryan
Created February 15, 2013 19:00
Show Gist options
  • Select an option

  • Save quidryan/4962525 to your computer and use it in GitHub Desktop.

Select an option

Save quidryan/4962525 to your computer and use it in GitHub Desktop.

Revisions

  1. quidryan created this gist Feb 15, 2013.
    39 changes: 39 additions & 0 deletions build.gradle
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    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+/
    }
    }