2013-10-02 70 views
0

我正在使用Gradle,並且需要對編譯階段進行一些預處理。我的預處理器是一個來自外部庫的類(從Maven Central加載的依賴項)。我怎麼寫這樣的task使用java代碼的Gradle自定義任務

我有這樣的代碼:

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

但搖籃看不到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

您必須像導入任何其他常規Java類一樣導入類。 –

回答

相關問題