Skip to content

Instantly share code, notes, and snippets.

@childnode
Last active June 24, 2016 09:55
Show Gist options
  • Save childnode/65da57ca1e9a54827366b43e2b37ae17 to your computer and use it in GitHub Desktop.
Save childnode/65da57ca1e9a54827366b43e2b37ae17 to your computer and use it in GitHub Desktop.
gradle.wrapper nail version for gradle and java
allprojects {
sourceCompatibility = JavaVersion.VERSION_1_8
tasks.withType(JavaCompile) { task ->
// nicify "invalid source release: 1.8" message:
task.doFirst {
if (("$System.env.JAVA_HOME".trim().isEmpty() || System.env.JAVA_HOME == null) && ("$System.env.JDK_HOME".trim().isEmpty() || System.env.JDK_HOME == null)) {
println ' WARNING: neither JAVA_HOME nor JDK_HOME set!'
}
if (!JavaVersion.current().equals(project.sourceCompatibility)) {
throw new IllegalStateException('Must be built with Java 8 or higher, is: ' + JavaVersion.current() + "\n (JAVA_HOME=\"$System.env.JAVA_HOME\")")
}
}
task.options.encoding = 'UTF-8'
}
}
def checkGradleVersionMatchesProjectDefinition() {
if (gradle.gradleVersion != wrapper.gradleVersion) {
throw new IllegalStateException('You are running this with gradle : ' + gradle.gradleVersion + " but it is set up with gradle wrapper " + wrapper.gradleVersion + ". PLEASE check usage of wrapper instead of local installed gradle!")
}
}
allprojects {
wrapper {
gradleVersion = '2.11'
}
defaultTasks 'clean', 'build'
clean.doFirst { checkGradleVersionMatchesProjectDefinition() }
build.doFirst { checkGradleVersionMatchesProjectDefinition() }
tasks.withType(JavaCompile) { task ->
task.doFirst {
checkGradleVersionMatchesProjectDefinition()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment