Gradle: Checking for SNAPSHOT dependencies on a release build

I swear that Gradle used to prevent you from uploading a SNAPSHOT dependency to Maven central in the past. If it ever did, it no longer does as I have screwed up a two times. The reason this is bad is that the SNAPSHOT will eventually expire breaking your project. Thought I was careful on my latest release of BoofCV, but I missed one reference.  Now I have to do a new incremental release, which is a pain and confusing for the users.

To overcome this problem I added the following code to my build.gradle file.  What it does is check all dependencies in each subproject for the word SNAPSHOT.  If one is found it throws an error explaining what happened.

subprojects {
    task checkDependsOnSNAPSHOT << {
        if (version.endsWith("SNAPSHOT"))
            return;

        project.configurations.compile.each {
            if (it.toString().contains("SNAPSHOT"))
                throw new Exception("Release build contains snapshot dependencies: " + it)
        }
    }
    jar.dependsOn checkDependsOnSNAPSHOT
}

This works in Gradle 3.2