问题
I'm using Gradle, and I need to make some preprocessing on compilation phase. My preprocessor is a class from an external library (a dependency, loaded from Maven Central). How can I wrote such task
?
I have code like:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
classpath group: 'com.googlecode.htmlcompressor', name: 'htmlcompressor', version: '1.4'
}
}
task compressXML {
logging.captureStandardOutput LogLevel.INFO
String xml = file('assets/menu.xml').text;
XmlCompressor compressor = new XmlCompressor();
String compressedXml = compressor.compress(xml);
println compressedXml;
}
but the problem that Gradle don't see XmlCompressor
class:
build.gradle': 70: unable to resolve class XmlCompressor
@ line 70, column 27.
XmlCompressor compressor = new XmlCompressor();
^
build file '../build.gradle': 70: unable to resolve class XmlCompressor
@ line 70, column 40.
XmlCompressor compressor = new XmlCompressor();
^
2 errors
回答1:
if you use JCP preprocessor then you can visit its page and there is wiki page how to make preprocessing with gradle for android projects
来源:https://stackoverflow.com/questions/19130743/gradle-custom-task-with-java-code