我的 build.gradle
好像:
apply plugin: 'war'
war {
...
}
我使用
gradle war
构建在配置阶段,我想运行
git submodule update --init --recursive
所以我将 build.gradle 更改为:
apply plugin: 'war'
task configured(type: Exec) {
commandLine "git submodule update --init --recursive"
}
war {
...
}
当我做
gradle war
:FAILURE:构建失败并出现异常。
无法确定任务 ':war' 的依赖关系。
我没有看到我的子模块正在更新。怎么了?
编辑:
我在 settings.gradle 中放入以下行
exec {
commandLine "git", "submodule", "update", "--init", "--recursive"
}
我删除了从 build.gradle 配置的任务。
你觉得那是一个很好的解决方案吗?
最佳答案
In the configuration phase, I want to run git submodule update --init --recursive
您当前的构建正在执行阶段执行此操作。为什么要在配置阶段做呢?请注意,这将减慢 Gradle 的每次调用速度。
I do not see my submodules being updated. What is wrong?
只有在命令行上指定的任务及其任务依赖项才会运行。如果不指定
configured
在命令行上,也不做(比如说)war
依赖它,它不会运行。What went wrong: Could not determine the dependencies of task ':war'.
显然,您的构建脚本的其余部分存在一些问题(您没有显示)。也许你正试图做一些类似
war.dependsOn(configured)
的事情。 , 并没有完全正确。
关于java - 无法使用 gradle war 插件运行 git submodule init,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21389142/