Skip to content

Instantly share code, notes, and snippets.

@radzio
Last active August 29, 2015 14:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radzio/e3cf23ff2fb276b7a6be to your computer and use it in GitHub Desktop.
Save radzio/e3cf23ff2fb276b7a6be to your computer and use it in GitHub Desktop.
Automatically sets JDK_1_8 in Android Studio java module
apply plugin: 'java'
apply plugin: 'idea'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
configurations {
// pending http://jira.codehaus.org/browse/GRADLE-471
providedCompile { description = 'Jars not to be included in the generated POM' }
}
sourceSets {
main {
compileClasspath += [configurations.providedCompile]
runtimeClasspath += [configurations.providedCompile]
}
test {
compileClasspath += [configurations.providedCompile]
runtimeClasspath += [configurations.providedCompile]
}
}
// add to idea classpath
// extracted from http://gradle.1045684.n5.nabble.com/Idea-project-generation-and-provided-scope-td4684287.html
idea.module {
scopes.PROVIDED.plus += [configurations.providedCompile]
scopes.COMPILE.minus += [configurations.providedCompile]
jdkName = '1.8'
iml.withXml {
def atts = it.asNode().component
.find { it.@name == 'NewModuleRootManager' }
.attributes()
println atts
atts.remove('LANGUAGE_LEVEL')
atts.put('LANGUAGE_LEVEL', 'JDK_1_8')
def newAtts = it.asNode().component
.find { it.@name == 'NewModuleRootManager' }
.attributes()
println newAtts
}
}
compileJava.dependsOn ideaModule
// add to javadoc and eclipse classpath
gradle.taskGraph.beforeTask { task ->
if (task.name == 'javadoc')
task.options.classpath = task.options.classpath + configurations.providedCompile.resolve()
if (task.name == 'eclipseClasspath')
task.plusConfigurations += configurations.providedCompile
}
dependencies {
// your dependencies
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment