Anrdoid Checkstyle 8.1错误:无法创建根模块

时间:2017-07-28 06:26:40

标签: android checkstyle

我想为Checkstyle撰写自定义支票。 Checkstyle使用他的标准模块成功运行,但当我尝试使用自定义模块运行它时,我收到错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkstyle'.
> Unable to create Root Module: config {D:\Users\...\config\checkstyle\checkstyle.xml}, classpath {null}.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

我使用Checkstyle Gradle plugin 这是我的gradle(模块:应用程序):

apply plugin: 'com.android.application'
apply plugin: "checkstyle"

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.webtrust.tennosushi"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        multiDexEnabled true  // this line will solve this problem (Без него вроде как идут ошибки на эмуляторе при испльзовании гугл карт)
        aaptOptions.cruncherEnabled = false // 2 линии для совместимости с дженкинсом
        aaptOptions.useNewCruncher = false
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
    }
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }
}


// Add checkstyle to the check task.
//check.dependsOn 'checkstyle'

checkstyle {
    configFile = new File("${rootProject.rootDir}/config/checkstyle/checkstyle.xml")
    toolVersion = '8.1'
}

task checkstyle(type: Checkstyle) {
    source 'src'
    include '**/*.java'
    exclude '**/gen/**'
    exclude '**/R.java'
    exclude '**/BuildConfig.java'

    def configProps = ['proj.module.dir': projectDir.absolutePath]
    configProperties configProps

    // empty classpath
    classpath = files()
}

preBuild.dependsOn('checkstyle')

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:support-v4:25.3.0'
    compile 'com.android.support:design:25.3.0'
    compile 'com.android.support:percent:25.3.0'
    compile 'com.android.support:gridlayout-v7:25.3.0'
    compile 'com.android.support:recyclerview-v7:25.3.0'
    compile 'com.android.support:cardview-v7:25.3.0'
    compile 'com.google.android.gms:play-services:10.2.6'
    compile 'com.google.android.gms:play-services-maps:10.2.6'
    compile 'com.github.aakira:expandable-layout:1.6.0@aar'
    compile 'co.lujun:androidtagview:1.1.4'
    compile 'com.google.code.gson:gson:2.8.1'
    testCompile 'junit:junit:4.12'
    compile 'com.puppycrawl.tools:checkstyle:8.1'
}

这是我的checkstyle.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC
    "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
    "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <module name="com.apptrust.checkstyle.LinesAfterClassJavadocCheck"/>
</module>

我的自定义检查:

package com.apptrust.checkstyle;

import com.puppycrawl.tools.checkstyle.api.*;

public class LinesAfterClassJavadocCheck extends AbstractCheck {
    private static final int DEFAULT_LINES = 0;
    private int max = DEFAULT_LINES;

    /**
     * Returns the default token a check is interested in. Only used if the
     * configuration for a check does not define the tokens.
     *
     * @return the default tokens
     * @see TokenTypes
     */
    @Override
    public int[] getDefaultTokens() {
        return new int[]{TokenTypes.BLOCK_COMMENT_END};
    }

    /**
     * The configurable token set.
     * Used to protect Checks against malicious users who specify an
     * unacceptable token set in the configuration file.
     * The default implementation returns the check's default tokens.
     *
     * @return the token set this check is designed for.
     * @see TokenTypes
     */
    @Override
    public int[] getAcceptableTokens() {
        return new int[0];
    }

    /**
     * Called to process a token.
     *
     * @param ast the token to process
     */
    @Override
    public void visitToken(DetailAST ast) {
        // find the OBJBLOCK node below the CLASS_DEF
        DetailAST objBlock = ast.findFirstToken(TokenTypes.LITERAL_CLASS);
        if (ast.getLine() != objBlock.getLine()+1) {
            throw new IllegalArgumentException("SUKA BLEAT");
        }
    }

    /**
     * The tokens that this check must be registered for.
     *
     * @return the token set this must be registered for.
     * @see TokenTypes
     */
    @Override
    public int[] getRequiredTokens() {
        return new int[0];
    }
}

我尝试使用自定义检查的checkstule示例 - 它也没有用。我怎么解决这个问题呢? 抱歉我的坏ENG。

更新: 我写了一个写堆栈跟踪:

    * Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:checkstyle'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:84)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:55)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
        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:46)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
        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.execute(DefaultTaskGraphExecuter.java:236)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228)
        at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:113)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
        at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
        at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:196)
        at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:193)
        at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:193)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102)
        at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71)
        at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:50)
        at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
        at org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner$1.execute(RunAsBuildOperationBuildActionRunner.java:43)
        at org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner$1.execute(RunAsBuildOperationBuildActionRunner.java:40)
        at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
        at org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:40)
        at org.gradle.tooling.internal.provider.runner.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:75)
        at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29)
        at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
        at org.gradle.util.Swapper.swap(Swapper.java:38)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
        at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
        at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
    Caused by: : Unable to create Root Module: config {D:\Users\rares\Downloads\TennoSushi\config\checkstyle\checkstyle.xml}, classpath {null}.
        at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.createRootModule(CheckstyleAntTask.java:421)
        at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.realExecute(CheckstyleAntTask.java:311)
        at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.execute(CheckstyleAntTask.java:294)
        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:382)
        at org.gradle.internal.metaobject.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:170)
        at org.gradle.internal.metaobject.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:163)
        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:53)
        at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:70)
        at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:52)
        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:46)
        at org.gradle.api.plugins.quality.Checkstyle.run(Checkstyle.java:141)
        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:123)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:632)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:615)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76)
        ... 78 more
    Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module com.apptrust.checkstyle.LinesAfterClassJavadocCheck - Unable to instantiate 'com.apptrust.checkstyle.LinesAfterClassJavadocCheck' class, it is also not possible to instantiate it as com.puppycrawl.tools.checkstyle.checks.annotationcom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.blockscom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.codingcom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.designcom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.headercom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.importscom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.indentationcom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.javadoccom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.metricscom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.modifiercom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.namingcom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.regexpcom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.sizescom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.whitespacecom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checkscom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.filefilterscom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.filterscom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.com.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.annotationcom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.blockscom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.codingcom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.designcom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.headercom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.importscom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.indentationcom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.javadoccom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.metricscom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.modifiercom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.namingcom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.regexpcom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.sizescom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.whitespacecom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checkscom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.filefilterscom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.filterscom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.com.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck. 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:461)
        at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:171)
        at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.createRootModule(CheckstyleAntTask.java:418)
        ... 105 more
    Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate 'com.apptrust.checkstyle.LinesAfterClassJavadocCheck' class, it is also not possible to instantiate it as com.puppycrawl.tools.checkstyle.checks.annotationcom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.blockscom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.codingcom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.designcom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.headercom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.importscom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.indentationcom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.javadoccom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.metricscom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.modifiercom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.namingcom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.regexpcom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.sizescom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checks.whitespacecom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.checkscom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.filefilterscom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.filterscom.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.puppycrawl.tools.checkstyle.com.apptrust.checkstyle.LinesAfterClassJavadocCheck, com.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.annotationcom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.blockscom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.codingcom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.designcom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.headercom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.importscom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.indentationcom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.javadoccom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.metricscom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.modifiercom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.namingcom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.regexpcom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.sizescom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checks.whitespacecom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.checkscom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.filefilterscom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.filterscom.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck, com.puppycrawl.tools.checkstyle.com.apptrust.checkstyle.LinesAfterClassJavadocCheckCheck. 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:184)
        at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:451)
        ... 107 more

1 个答案:

答案 0 :(得分:1)

特别感谢@thomasJensen xxx提供价格建议

以下是good tutorial如何使用带有gradle的checkstyle,但仅限于checkstyle版本6.3

以下是基于本教程但使用8.1 checkstyle verison

的gradle脚本

Project build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

App module build.gradle

apply plugin: 'com.android.application'
apply plugin: 'checkstyle'

android {
    compileSdkVersion 21
    buildToolsVersion '25.0.0'

    defaultConfig {
        applicationId "com.lsurvila.checkstylebuilder"
        minSdkVersion 16
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

task checkstyle(type: Checkstyle) {
    configFile = rootProject.file('config/checkstyle/checkstyle.xml')

    source 'src/main/java'
    include '**/*.java'
    exclude '**/gen/**'

    // empty classpath
    classpath = files()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'

    // for testing/creating checkstyle rules
    checkstyle project(':custom-checkstyle')

    // for using compiled version
    //checkstyle 'com.puppycrawl.tools:checkstyle:6.3'
    //checkstyle files('../config/checkstyle/custom-checkstyle.jar')
}

custom-checkstyle modul build.gradle:

apply plugin: 'java'

jar {
    destinationDir rootProject.file('config/checkstyle')
}

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.puppycrawl.tools:checkstyle:8.1'
}

我的项目结构的屏幕截图: enter image description here

如果您也有问题风格问题,请与我联系。我会尽力帮助你,因为checkstyle设置很无聊