Last active
August 29, 2015 14:11
-
-
Save trevorrjohn/4c7d35b609e5701eaaa5 to your computer and use it in GitHub Desktop.
gradle task to fix dependency order in Android Studio
This file contains 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: 'idea' | |
idea { | |
module { | |
testOutputDir = file('build/test-classes') | |
} | |
} | |
task initGradleTest << { | |
def imlFile = '<path to iml>.iml' | |
def parse = new XmlParser().parse(imlFile) | |
def modulePath = parse.@'external.linked.project.path' | |
// It's Robolectric Default ouputPath | |
def outputTestPath = "file://$modulePath/build/test-classes" | |
def moduleComponent = parse.component.find { it.@name == 'NewModuleRootManager' } | |
def outputTest = moduleComponent.find {it.name() == 'output-test'} | |
if (outputTest != null) { | |
outputTest.@url = outputTestPath | |
} else { | |
moduleComponent.appendNode('output-test', [url : outputTestPath]) | |
} | |
// jdk orderEntry must be last | |
def orderEntry = moduleComponent.orderEntry | |
def jdkOrderEntry = orderEntry.find { it.@type == 'jdk' } | |
moduleComponent.remove(jdkOrderEntry) | |
moduleComponent.append(jdkOrderEntry) | |
// rewrite $project.iml file | |
FileWriter fileWriter = new FileWriter(imlFile) | |
new XmlNodePrinter(new PrintWriter(fileWriter)).print(parse) | |
} | |
tasks.preBuild.dependsOn initGradleTest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment