2

从我的 gradle 构建中,我想使用 html 压缩器将我的 html 缩小为构建过程的一部分,它作为 maven 工件存在:http ://code.google.com/p/htmlcompressor/#Maven_Artifact

jar 应该从 maven Central 加载,并且新版本应该在发布时自动使用。

如何做到这一点?

4

2 回答 2

3

目前,没有 Gradle 插件可以简化我所知道的这项任务。我认为如果您能写一个并将其贡献给社区,那就太好了。现在您可能可以使用htmlcompressor 提供的Ant 任务。在运行任务之前确保输入和输出目录确实存在。依赖项定义中的版本限定符允许您通过使用加号来拉取较新的版本,例如1.+. 我不建议这样做,因为如果 Ant 任务定义随新版本发生变化,它可能会破坏您的构建。

configurations {
    htmlcompressor
}

repositories {
    mavenCentral()
}

dependencies {
    htmlcompressor 'com.googlecode.htmlcompressor:htmlcompressor:1.4'
}

task compressHtml << {
    ant.apply(executable: "java", parallel: false) {
        fileset(dir: "test", includes: "*.html") {
            exclude(name: "**/leave/**")
        }

        arg(value: "-jar")
        arg(path: configurations.htmlcompressor.asPath)
        arg(line: "--type html")
        arg(value: "--preserve-comments")
        srcfile()
        arg(value: "-o")
        mapper(type: "glob", from: "*", to: "compressed/*")
        targetfile()
    }
}

编辑:您实际上不需要将依赖项添加到脚本的类路径中。为它使用配置要干净得多。我更改了脚本以反映这一点。

于 2012-06-25T13:01:39.300 回答
0

jar 应该从 maven Central 加载,并且新版本应该在发布时自动使用。

可以使用以下依赖项完成:

dependencies {
    htmlcompressor 'com.googlecode.htmlcompressor:htmlcompressor:latest.integration'
}
于 2012-06-26T15:03:00.630 回答