如何覆盖任务使其依赖于我的一个任务 [英] how to override a task making it depend on one of mine in gradle

查看:159
本文介绍了如何覆盖任务使其依赖于我的一个任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着按照gradle手册的例子来做这个例子,但是copyJars在eclipse任务之前并没有运行。 (eclipse任务来自eclipse插件)

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $
$ b $ .collection = files {genLibDir.listFiles()}
删除ext.collection
复制{从configurations.confile到genLibDir}
copy {from fixedLibDir into genLibDir}
}

eclipse.dependsOn = copyJars

任务('setupAll',dependsOn:'eclipse'){
description ='从远程仓库更新jar,然后修复eclipse classpath for stbldfiles project'
}


解决方案

这个构建脚本的问题:


  • eclipse 不涉及任务,但到同名的模型对象。 (你不会得到 eclipse.dependsOn ?的异常)
  • 任务 copyJars 在配置阶段执行它的工作,而不是在执行阶段(即对于每个构建,即使任务未执行)


为了解决这个问题,使用 tasks.eclipse.dependsOn(copyJars)任务copyJars<< {...}



另一个问题是,如果没有比用复制东西简单的方法, copyJars 并在事后修复Eclipse类路径,但我需要更多信息才能说明。


I tried following the gradle manual with their example like this but copyJars is not run at all before the eclipse task. (the eclipse task comes from the eclipse plugin)

task('copyJars') { 

    ext.collection = files { genLibDir.listFiles() }
    delete ext.collection
    copy { from configurations.compile into genLibDir }
    copy { from fixedLibDir into genLibDir }
}

eclipse.dependsOn = copyJars

task('setupAll', dependsOn: 'eclipse') {
    description = 'Update jars from remote repositories and then fix eclipse classpath for stbldfiles project'
}

解决方案

There are some problems with this build script:

  • eclipse doesn't refer to the task but to the equally named model object. (Don't you get an exception for eclipse.dependsOn?)
  • Task copyJars does its work in the configuration phase rather than the execution phase (i.e for every build, even if the task isn't executed)

To fix that, use tasks.eclipse.dependsOn(copyJars) and task copyJars << { ... }.

Another question is if there isn't a simpler way than copying things around with copyJars and fixing up the Eclipse class path after the fact, but I'd need more information to be able to tell.

这篇关于如何覆盖任务使其依赖于我的一个任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆