代码之家  ›  专栏  ›  技术社区  ›  hotmeatballsoup

默认情况下,Gradle CheckStyle插件与Google检查不兼容

  •  4
  • hotmeatballsoup  · 技术社区  · 7 年前

    请注意: 我创造了 this GitHub project to help you exactly produce the issue .


    这里是Java 8和Gealle 4.6。如果您创建了一个新的Java分级项目 gradle init --type java-library 然后将Gradle CheckStyle插件配置为使用 Google's Checkstyle XML 它将立即失效:

    plugins {
        id 'java-library'
    }
    
    apply plugin: 'checkstyle'
    
    dependencies {
        testCompile(
            'junit:junit:4.12'
        )
    }
    
    repositories {
        jcenter()
        mavenCentral()
    }
    
    checkstyle {
        // Go to the Google Checks link above and paste its
        // contents into checkstyle.xml
        config = rootProject.resources.text.fromFile('buildConfig/checkstyle/checkstyle.xml')
    }
    

    用这个配置,运行 ./gradle clean build 生产:

    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':checkstyleMain'.
    > Unable to create a Checker: configLocation {/Users/myuser/workspace/test-gradle-checkstyle/buildConfig/checkstyle/checkstyle.xml}, classpath {/Users/myuser/workspace/test-gradle-checkstyle/build/classes/java/main:/Users/myuser/workspace/test-gradle-checkstyle/build/resources/main}.
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    
    * Get more help at https://help.gradle.org
    
    BUILD FAILED in 1s
    4 actionable tasks: 4 executed
    $ pwd
    /Users/myuser/workspace/test-gradle-checkstyle
    $ git init
    Initialized empty Git repository in /Users/myuser/workspace/test-gradle-checkstyle/.git/
    

    我想知道为什么?!


    编辑(对于未来的谷歌用户):

    使用 --stacktrace ,实际误差为

    cannot initialize module TreeWalker - Token "METHOD_REF" was not found in Acceptable tokens list in check com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck
    
    1 回复  |  直到 6 年前
        1
  •  9
  •   Helder Pereira Arjit    6 年前

    --stacktrace -S

    cannot initialize module TreeWalker - Token "METHOD_REF" was not found in Acceptable tokens list in check com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck
    

    checkstyle {
        config = rootProject.resources.text.fromFile('buildConfig/checkstyle/checkstyle.xml')
        toolVersion '8.11'
    }
    

    > Task :checkstyleMain
    [ant:checkstyle] [WARN] /.../test-gradle-checkstyle/src/main/java/Library.java:5: 'method def modifier' has incorrect indentation level 4, expected level should be 2. [Indentation]
    [ant:checkstyle] [WARN] /.../test-gradle-checkstyle/src/main/java/Library.java:6: 'method def' child has incorrect indentation level 8, expected level should be 4. [Indentation]
    [ant:checkstyle] [WARN] /.../test-gradle-checkstyle/src/main/java/Library.java:7: 'method def rcurly' has incorrect indentation level 4, expected level should be 2. [Indentation]
    
    > Task :checkstyleTest
    [ant:checkstyle] [WARN] /.../test-gradle-checkstyle/src/test/java/LibraryTest.java:5: 'import' should be separated from previous statement. [EmptyLineSeparator]
    [ant:checkstyle] [WARN] /.../test-gradle-checkstyle/src/test/java/LibraryTest.java:5: Import statement for 'org.junit.Assert.*' is in the wrong order. Should be in the 'STATIC' group, expecting not assigned imports on this line. [CustomImportOrder]
    [ant:checkstyle] [WARN] /.../test-gradle-checkstyle/src/test/java/LibraryTest.java:5: Using the '.*' form of import should be avoided - org.junit.Assert.*. [AvoidStarImport]
    [ant:checkstyle] [WARN] /.../test-gradle-checkstyle/src/test/java/LibraryTest.java:8: 'method def modifier' has incorrect indentation level 4, expected level should be 2. [Indentation]
    [ant:checkstyle] [WARN] /.../test-gradle-checkstyle/src/test/java/LibraryTest.java:9: 'method def' child has incorrect indentation level 8, expected level should be 4. [Indentation]
    [ant:checkstyle] [WARN] /.../test-gradle-checkstyle/src/test/java/LibraryTest.java:10: 'method def' child has incorrect indentation level 8, expected level should be 4. [Indentation]
    [ant:checkstyle] [WARN] /.../test-gradle-checkstyle/src/test/java/LibraryTest.java:11: 'method def rcurly' has incorrect indentation level 4, expected level should be 2. [Indentation]
    
    
    BUILD SUCCESSFUL in 9s
    7 actionable tasks: 7 executed