要在Gradle Task / Groovy函数中访问Ant属性?

问题描述 投票:0回答:1

我正在尝试在gradle函数中使用ant.uptodate函数,以检查某些文件是否已更改。

task generateXMLBeans {
    ant.uptodate(property: "xsdFileChanges", targetfile: "lib/xmlBeans.jar") {
            srcfiles(dir: 'protocol') {
                include(name: '*.xsd')
            }
    }
    if(ant.properties.xsdFileChanges == "false") {
        ant.taskdef(name: 'xmlbean', classname: 'org.apache.xmlbeans.impl.tool.XMLBean',
            classpath: configurations.xmlbeans.asPath)
            ant.xmlbean(
                javasource: "1.5", 
                failonerror: "true",
                fork: "yes",
                memoryMaximumSize: "512M",
                memoryInitialSize: "64M",
                destfile: "lib/xmlBeans.jar",
                classpath: configurations.xmlbeans.asPath){
                    fileset(dir: 'protocol') {
                        include(name: '*.xsdconfig')
                        include(name: 'hmiprotocol.xsd')
                    }
                }    
    }
}

但是变量ant.properties.xsdFileChangesnull

我试图将ant.uptodate函数放在一个单独的函数中,并得到相同的结果。

[当我使用--debug函数调用任务时,可以看到ant.uptodate函数通常可以正常工作。

14:40:50.947 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:uptodate] hmiprotocol_systemlog.xsd omitted as D:\workspace_201912\ProjectX\lib\xmlBeans.jar is up to date.
14:40:50.948 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:uptodate] hmiprotocol_testdetails.xsd omitted as D:\workspace_201912\ProjectX\lib\xmlBeans.jar is up to date.

有人有什么主意,我如何才能正确访问ant属性?

gradle ant
1个回答
0
投票

这与在Gradle中使用Ant无关;这就是Ant的uptodate属性的工作方式。如果文件不是最新的,则指定的属性未设置为false。根本没有设置。其他一些Ant任务,例如condition,也使用相同的约定。

一个简单的示例,您可以尝试使用Ant本身,因为您在同一目录中同时拥有一个build.xml和build.gradle文件:

<target name="default">
    <uptodate property="uptodate1" targetfile="build.xml" srcfile="build.gradle" />

    <echo>${uptodate1}</echo>

    <uptodate property="uptodate2" targetfile="build.gradle" srcfile="build.xml" />

    <echo>${uptodate2}</echo>
</target>

输出(根据修改的时间可能会反转):

default:
     [echo] true
     [echo] ${uptodate2}
© www.soinside.com 2019 - 2024. All rights reserved.