Gradle custom task with java code

佐手、 提交于 2021-02-08 11:51:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!