问题描述
我想在我的gradle项目中使用checkstyle插件,gradle文档说它将添加一些任务:
i want to use checkstyle plugin in my gradle project, the gradle documentation says that it will add a few tasks:https://docs.gradle.org/current/userguide/checkstyle_plugin.html
checkstyleMain, checkstyleTest, checkstyleSourceSet
我将其添加到我的应用程序build.gradle文件中:
I added this into my app build.gradle file:
apply plugin: 'checkstyle'
我想从cmd运行gradle任务以执行代码样式检查,但是没有一个checkstyle任务。我通过键入以下内容检查了整个列表:
I want to run gradle task from cmd to perform code style check, but there are no one checkstyle task. I checked the whole list by typing:
./gradlew tasks
我还尝试将checkstyle jar作为库依赖项添加到应用程序模块。
谁能告诉我我在做错什么以及如何获得我的样式检查任务?
I also tried to add checkstyle jar as library dependency to app module.Can anyone tell me what i am doing wrong and how can i get my checkstyle tasks?
推荐答案
checkstyle插件将其任务添加到其他任务虚拟任务组中。这些实际上是尚未 分配给任务组的任务。因此,它们仅在您运行 ./ gradlew任务--all
(请注意-all
)时显示。
Well, the checkstyle plugin adds its tasks in the Other tasks virtual task group. Those are really the tasks which have not been assigned to a task group. So, they are shown only when you run ./gradlew tasks --all
(note the --all
).
完成工作 build.gradle :
apply plugin: 'java';
apply plugin: 'checkstyle';
然后运行 ./ gradlew任务--all
,输出:
<...snip...>
Other tasks
-----------
checkstyleMain - Run Checkstyle analysis for main classes
checkstyleTest - Run Checkstyle analysis for test classes
<...snip...>
如果您想显示Checkstyle任务而没有-全部
,然后将它们分配给任务组,例如:
If you want the Checkstyle tasks to appear without --all
, then assign them to a task group, for example:
tasks.withType(Checkstyle).each {
it.group = 'verification'
}
这篇关于Checkstyle插件不添加Gradle任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!