使用java代码Gradle自定义任务

时间:2013-10-02 05:52:46

标签: android gradle

我正在使用Gradle,我需要在编译阶段进行一些预处理。我的预处理器是来自外部库的类(从Maven Central加载的依赖项)。我怎么能写这样的task

我的代码如下:

  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;
                }

但是Gradle看不到XmlCompressor类的问题:

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 个答案:

答案 0 :(得分:0)