Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

android - Checkstyle, Unable to create Root Module

I'm trying to configure Checkstyle in the project. I've added:

    apply plugin: 'checkstyle'
    checkstyle {
        // assign the latest checkstyle version explicitly
        // default version is very old, likes 5.9
        toolVersion = '8.6'
        // checkstyle.xml copy from:
        // https://raw.githubusercontent.com/checkstyle/checkstyle/checkstyle-8.6/src/main/resources/google_checks.xml
        // the version should be as same as plugin version
        configFile = rootProject.file('config/checkstyle/checkstyle.xml')
    }
    task Checkstyle(type: Checkstyle) {
        source 'src/main/java'
        include '**/*.java'
        exclude '**/gen/**'
        exclude '**/R.java'
        exclude '**/BuildConfig.java'

        // empty classpath
        classpath = rootProject.files()
    }

to my root gradle file in allprojects.

But when I run ./gradlew checkstyle

I get:

* What went wrong:
Execution failed for task ':app:Checkstyle'.
> Unable to create Root Module: config {/Users/user/Development/project/config/checkstyle/checkstyle.xml}, classpath {null}.

Even the file with rules is located in specified dir.

question from:https://stackoverflow.com/questions/49645147/checkstyle-unable-to-create-root-module

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This happened to me when I updated Android Gradle Plugin to 3.3.0

Please run this:

./gradlew checkstyle --stacktrace

Probably you will need to check your checkstyle.xml config file.

I needed to move those two tags:

 <module name="SuppressionCommentFilter"/>

        <!--Enable usage SUPPRESS CHECKSTYLE comment-->
        <module name="SuppressWithNearbyCommentFilter">
            <property name="commentFormat" value="CHECKSTYLE IGNORE"/>
            <property name="checkFormat" value=".*"/>
            <property name="influenceFormat" value="0"/>
        </module>

inside

<module name="TreeWalker"> 

tag

Also I needed to remove:

<module name="SuppressionCommentFilter"/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...