我有 gradle 项目,有 4 个子项目。我有当前的根 gradle.build 和 checkstyle:
allprojects {
apply plugin: "checkstyle"
checkstyle {
...
}
}
所以当我在主文件夹中运行 ./gradlew build 时,我得到下一个: 检查第一个子项目的样式,然后进行测试。然后它为第二个子项目运行 checkstyle,然后测试第二个子项目,依此类推。
问题是:如果我在第一个子项目中有很长的测试,我可以等待很多时间,然后发现我在第四个项目中有2个空格,所以 checkstyle 失败,但我等待了很多时间.
我真正想要的: 对所有子项目运行所有检查(checkstyle,我也有 pmd),然后在所有子项目中运行所有测试。这将为团队中的每个人节省大量时间。
除了创建两个不同的管道并分别运行它们之外,我可以这样做吗?像: ./gradlew allMyCheckstyles && ./gradlew build. 我很想只使用 ./gradlew build 谢谢!
我尝试了很多dependOn、runAfter,但没有成功。
最佳答案
抱歉,此答案的先前版本误解了此问题的要求。
这是一个可以满足您要求的解决方案:
// Create a lifecycle task in the root project.
// We'll make this depend on all checkstyle tasks from subprojects (see below)
def checkstyleAllTask = task("checkstyleAll")
// Make 'check' task depend on our new lifecycle task
check.dependsOn(checkstyleAllTask)
allProjects {
// Ensure all checkstyle tasks are a dependency of the "checkstyleAll" task
checkstyleAllTask.dependsOn(tasks.withType(Checkstyle))
tasks.withType(Test) {
// Indicate that testing tasks should run after the "checkstyleAll" task
shouldRunAfter(checkstyleAllTask)
// Indicate that testing tasks should run after any checksytle tasks.
// This is useful for when you only want to run an individual
// subproject's checks (e.g. ./gradlew ::subprojA::check)
shouldRunAfter(tasks.withType(Checkstyle))
}
}
关于java - 在所有子项目中的所有测试之前运行子项目中的 checkstyles,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57803277/