我想检查一下我项目的代码风格。然后我应用checkstyle
插件。在build.gradle
根项目中,我在每个子项目中添加了一个新任务。
subprojects { project ->
apply plugin: 'checkstyle'
task checkstyle(type: Checkstyle) {
description 'Runs Checkstyle inspection against ICanPlayer sourcesets.'
group = 'Code Quality'
configFile rootProject.file('checkstyle.xml')
ignoreFailures false
showViolations true
classpath = files()
source 'src/main/java'
}
afterEvaluate {
check.dependsOn('checkstyle')
}
}
当我执行./gradlew check
时无法正常工作。这是错误输出。
* What went wrong:
Execution failed for task ':app:checkstyle'.
> Unable to create a Checker: configLocation {/Users/lijianxin/AndroidStudioProjects/Girl/checkstyle.xml}, classpath {null}.
我对这个错误感到非常疯狂,因为如你所见,我设置了classpath
。好的,我也搜索了这个错误,我得到了一个类似的问题https://discuss.gradle.org/t/unable-to-create-a-checker-configlocation/13216。
checkstyle {
classpath = files()
}
这是完整的日志。
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:checkstyle'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: : Unable to create a Checker: configLocation {/Users/lijianxin/AndroidStudioProjects/Girl/checkstyle.xml}, classpath {null}.
at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.createChecker(CheckstyleAntTask.java:425)
at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.realExecute(CheckstyleAntTask.java:320)
at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.execute(CheckstyleAntTask.java:303)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.gradle.api.internal.project.ant.BasicAntBuilder.nodeCompleted(BasicAntBuilder.java:78)
at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:479)
at org.gradle.internal.metaobject.BeanDynamicObject.tryInvokeMethod(BeanDynamicObject.java:191)
at org.gradle.internal.metaobject.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:160)
at org.gradle.api.internal.project.antbuilder.AntBuilderDelegate.nodeCompleted(AntBuilderDelegate.java:118)
at org.gradle.api.plugins.quality.internal.CheckstyleInvoker$_invoke_closure1.doCall(CheckstyleInvoker.groovy:58)
at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:71)
at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:53)
at org.gradle.api.internal.project.antbuilder.DefaultIsolatedAntBuilder$2.execute(DefaultIsolatedAntBuilder.java:151)
at org.gradle.api.internal.project.antbuilder.DefaultIsolatedAntBuilder$2.execute(DefaultIsolatedAntBuilder.java:133)
at org.gradle.api.internal.project.antbuilder.ClassPathToClassLoaderCache.withCachedClassLoader(ClassPathToClassLoaderCache.java:134)
at org.gradle.api.internal.project.antbuilder.DefaultIsolatedAntBuilder.execute(DefaultIsolatedAntBuilder.java:127)
at org.gradle.api.internal.project.IsolatedAntBuilder$execute$0.call(Unknown Source)
at org.gradle.api.plugins.quality.internal.CheckstyleInvoker.invoke(CheckstyleInvoker.groovy:51)
at org.gradle.api.plugins.quality.Checkstyle.run(Checkstyle.java:148)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.doExecute(DefaultTaskClassInfoStore.java:141)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:731)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:705)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
... 27 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module TreeWalker - Unable to instantiate 'RedundantThrows' class, it is also not possible to instantiate it as com.puppycrawl.tools.checkstyle.checks.annotation.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.blocks.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.coding.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.design.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.header.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.imports.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.indentation.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.javadoc.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.metrics.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.modifier.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.naming.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.regexp.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.sizes.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.whitespace.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.RedundantThrows, com.puppycrawl.tools.checkstyle.filters.RedundantThrows, com.puppycrawl.tools.checkstyle.RedundantThrows, RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.annotation.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.blocks.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.coding.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.design.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.header.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.imports.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.indentation.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.javadoc.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.metrics.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.modifier.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.naming.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.regexp.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.sizes.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.whitespace.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.filters.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.RedundantThrowsCheck. Please recheck that class name is specified as canonical name or read how to configure short name usage http://checkstyle.sourceforge.net/config.html#Packages. Please also recheck that provided ClassLoader to Checker is configured correctly.
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:407)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:138)
at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.createChecker(CheckstyleAntTask.java:422)
... 59 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate 'RedundantThrows' class, it is also not possible to instantiate it as com.puppycrawl.tools.checkstyle.checks.annotation.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.blocks.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.coding.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.design.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.header.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.imports.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.indentation.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.javadoc.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.metrics.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.modifier.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.naming.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.regexp.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.sizes.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.whitespace.RedundantThrows, com.puppycrawl.tools.checkstyle.checks.RedundantThrows, com.puppycrawl.tools.checkstyle.filters.RedundantThrows, com.puppycrawl.tools.checkstyle.RedundantThrows, RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.annotation.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.blocks.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.coding.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.design.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.header.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.imports.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.indentation.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.javadoc.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.metrics.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.modifier.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.naming.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.regexp.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.sizes.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.whitespace.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.checks.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.filters.RedundantThrowsCheck, com.puppycrawl.tools.checkstyle.RedundantThrowsCheck. Please recheck that class name is specified as canonical name or read how to configure short name usage http://checkstyle.sourceforge.net/config.html#Packages. Please also recheck that provided ClassLoader to Checker is configured correctly.
at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:99)
at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:153)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:138)
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:402)
... 61 more
答案 0 :(得分:0)
我有多傻。日志告诉我为什么我错了。只需从checkstyl.xml中删除<module name="RedundantThrows"/>
。
答案 1 :(得分:0)
升级checkstyle toolVersion(在撰写本文时为8.17)对我来说很有效。
checkstyle {
toolVersion "8.17"
}