从另一个任务调用gradle eclipse任务

时间:2016-02-29 11:18:29

标签: eclipse gradle import gradlew

我正在使用的一个git存储库包含50多个eclipse项目,这些项目都是在./gradlew eclipse的工作副本中生成的(eclipse的东西不受源代码控制)。当在分支或提交之间切换时,这些项目的集合有时会发生变化。在./gradlew eclipse工作之后调用git checkout,但它只创建新发现的项目。

提交中不再存在的项目已变为孤儿 - 不再需要.eclipse.classpath.settings保留在目录树中。因此,Eclipse中的导入现有项目向导会执行错误,并且工作空间中的某些依赖项也会损坏。

我尝试编写一个gradle任务,删除所有现有的eclipse文件,然后使用标准的eclipse任务重新创建它们。最后,我想删除repo根目录中的eclipse文件,以便导入向导显示所有项目,无需勾选搜索嵌套项目

// /.gradlew eclipse does not remove old projects' eclipse files
// so there is a chance of importing a deleted project to eclipse after its removal.
// This creates name conflicts and failures in eclipse build.
// /.gradlew eclipsex fixes this issue

task deleteEclipseStuffInAllDirs(type: Delete) {
  delete fileTree(dir: '.' , include: '**/.project')
  delete fileTree(dir: '.' , include: '**/.classpath')
  delete fileTree(dir: '.' , include: '**/.settings/*') // could not find how to delete such dirs themselves
}

task deleteEclipseStuffInRootDir(type: Delete) {
  delete fileTree(dir: '.' , include: '.project')
  delete fileTree(dir: '.' , include: '.classpath')
  delete '.settings'
}
deleteEclipseStuffInRootDir.dependsOn(":eclipse")

task eclipsex() {
}
eclipsex.dependsOn(":deleteEclipseStuffInAllDirs")
eclipsex.dependsOn(":eclipse")
eclipsex.dependsOn(":deleteEclipseStuffInRootDir")

尽管我设置了所有依赖项,但eclipse命令并不总是被执行。我该怎么强迫它?

P.S:我知道存在./gradlew cleanEclipse,但由于某种原因它不会删除孤立的eclipse文件。

UPD:控制台输出:

$ ./gradlew eclipse
Starting a new Gradle Daemon for this build (subsequent builds will be faster).
Parallel execution with configuration on demand is an incubating feature.
:eclipseClasspath
:back-end:proj1:eclipseClasspath
:back-end:proj2:eclipseClasspath
:back-end:proj3:eclipseClasspath
...
:front-end:proj42:eclipseJdt
:front-end:proj42:eclipseProject
:front-end:proj42:eclipse

BUILD SUCCESSFUL

Total time: 13.677 secs

$ ./gradlew eclipsex
Parallel execution with configuration on demand is an incubating feature.
:deleteEclipseStuffInAllDirs
:eclipseClasspath
:eclipseJdt
:eclipseProject
:eclipse
:deleteEclipseStuffInRootDir
:eclipsex

BUILD SUCCESSFUL

Total time: 3.788 secs

0 个答案:

没有答案