我们有一个旧的ant构建系统,它仍然有必要继续使用。当我们将功能迁移到gradle时,我们仍然在gradle中调用一些更有用的ant目标。其中一个有用的ant目标是报告摘要附加器,它可以使用生成的任何报告更新索引文件。
我正在将checkstyle添加到我们的gradle构建中,并尝试为checkstyle生成的每个报告调用此目标。但是,我似乎不知道如何从gradle多次调用该ant目标,但是具有不同的属性,因为Ant属性似乎对于整个构建是全局的。
目前为止我得到的信息是:
ant.importBuild('build.xml') { antTargetName ->
'ant-' + antTargetName
}
checkstyleMain {
doLast {
ant.properties['report.prop1'] = 'foo'
ant.properties['report.prop2'] = 'bar'
ant.properties['report.prop3'] = 'war'
}
}
checkstyleMain.finalizedBy 'ant-report-summary'
checkstyleTest {
doLast {
ant.properties['report.prop1'] = 'aaa'
ant.properties['report.prop2'] = 'bbb'
ant.properties['report.prop3'] = 'ccc'
}
}
checkstyleTest.finalizedBy 'ant-report-summary'
check.dependsOn checkstyleMain, checkstyleTest
这在我运行check
时不起作用,因为ant-report-summary
只执行一次(gradle认为它不需要运行同一个任务3次),所以只使用上次运行的checkstyle任务的属性:
> Task :checkstyleMain
...
> Task :checkstyleTest
> Task :ant-report-summary
我希望每个checkstyle任务都运行一次ant-report-summary
,并使用doLast
中指定的属性。
1条答案
按热度按时间qv7cva1a1#
工作示例here
我无法让它与
AntBuilder
一起工作(许多脑细胞死亡),所以我的方法将属性外包给Ant端。其中,
main.properties
和test.properties
与预期一致。那么,如果我们使用Exec
任务,事情就简单一些。用于调用Ant的基类任务(**注:**为重构而编辑):
和特定任务(以下命令行适用于Unix,但可以轻松更改为Windows):
然后:
并且在我的工作示例中,
./gradlew clean check
将调用Ant两次。