gpt4 book ai didi

groovy - Gradle ant 构建文件在配置阶段不可用

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

我不知道如何执行 ant target 以防 ant build.xml 文件在配置阶段不可用 .因为它是一个远程资源(Maven 远程资源插件)。

所以基本上首先我需要像这样获取这个远程资源:

configurations {
remoteResources
}

dependencies.remoteResources 'group:my-remote-resource:version'

task getRemoteResources(type: Copy) {
from(zipTree(configurations.remoteResources.first()))
into("$buildDir/remote-resources")

// replace placeholders
filter(org.apache.tools.ant.filters.ReplaceTokens, , tokens: remotePlaceholders)
}

只有这样我才有 build.xml
"$buildDir/remote-resources"

但是我不能使用 ant.importBuild 因为这期望 build.xml 在配置期间可用,这不是我的情况。

我正在考虑将远程资源“下载”移动到初始化阶段,但我有一个多模块项目,虽然只有一些子项目正在使用这个远程资源,但它们都有自己的占位符来替换。

在这种特殊情况下,有什么方法可以执行 ant 目标吗?

编辑:我发现很不错 solution利用 Ant 的 ProjectHelper 和 Project 类。所以我想这就是我的答案..

最佳答案

所以这是最终的解决方案。 (正如已经提到的学分转到 groovy-almanac )

import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;

task executeAntTarget(dependsOn: getRemoteResources) << {
def antFile = new File("$buildDir/remote-resources/build.xml")
def antProject = new Project()
antProject.init()
ProjectHelper.projectHelper.parse(antProject, antFile)

antProject.executeTarget('<target-to-execute>');
}

关于groovy - Gradle ant 构建文件在配置阶段不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34471547/

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