gpt4 book ai didi

maven - Gradle - 从 Maven 加载 jar 并用作构建的一部分

转载 作者:行者123 更新时间:2023-12-03 03:10:24 25 4
gpt4 key购买 nike

从我的 gradle 构建中,我想在构建过程中使用 html 压缩器来缩小我的 html,它作为 Maven Artifact 存在:http://code.google.com/p/htmlcompressor/#Maven_Artifact

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

如何做到这一点?

最佳答案

目前,没有 Gradle 插件可以简化我所知道的这项任务。我认为如果你能写一篇并将其贡献给社区,那就太好了。现在你可能可以使用 Ant tasks由 htmlcompressor 提供。在运行任务之前确保输入和输出目录确实存在。依赖项定义中的版本限定符允许您使用加号来拉取更新的版本,例如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()
}
}

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

关于maven - Gradle - 从 Maven 加载 jar 并用作构建的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11187468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com