【问题标题】:Gradle ant build file not not available during configuration phaseGradle ant 构建文件在配置阶段不可用
【发布时间】:2016-04-01 00:08:18
【问题描述】:

如果在配置阶段 ant build.xml 文件不可用,我不知道如何执行 ant 目标。因为它是一个远程资源(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 gradle ant build.gradle


【解决方案1】:

所以这是最终的解决方案。 (如前所述,学分转到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>');
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-15
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    • 2014-11-20
    相关资源
    最近更新 更多