等级检查样式错误:预期的文件集合仅包含一个文件,但是,它包含14个文件

问题描述 投票:1回答:1

我正在将Java 8与Gradle结合使用,并尝试将Google Checkstyle规则添加到内部版本中,但是出现的错误是:

“预期的文件集合仅包含一个文件,但是,它包含14个文件。”

我的配置是:

apply plugin: 'checkstyle'
configurations {
  checkstyleConfig
}
def versions = [
  checkstyle: '8.8',
]
dependencies {
  checkstyleConfig "com.puppycrawl.tools:checkstyle:${versions.checkstyle}"
}
checkstyle {
  toolVersion = "${versions.checkstyle}"
  config = resources.text.fromArchiveEntry(configurations.checkstyleConfig, 'google_checks.xml')
}
gradle build.gradle checkstyle
1个回答
0
投票

这里的问题是configurations.checkstyleConfig包含多个JAR文件:com.puppycrawl.tools:checkstyle以及其所有传递依赖项。在本地调试问题,我发现这些依赖项已包括在内:

antlr:antlr:2.7.7
com.google.code.findbugs:jsr305:1.3.9
com.google.errorprone:error_prone_annotations:2.1.3
com.google.guava:guava:23.6-jre
com.google.j2objc:j2objc-annotations:1.1
com.puppycrawl.tools:checkstyle:8.8
commons-beanutils:commons-beanutils:1.9.3
commons-cli:commons-cli:1.4
commons-collections:commons-collections:3.2.2
commons-logging:commons-logging:1.2
net.sf.saxon:Saxon-HE:9.8.0-7
org.antlr:antlr4-runtime:4.7.1
org.checkerframework:checker-compat-qual:2.0.0
org.codehaus.mojo:animal-sniffer-annotations:1.14

幸运的是,此修复非常简单。您需要做的就是从Checkstyle依赖项中排除传递性依赖项,脚本的其余部分将按照您希望的方式工作:

dependencies {
    checkstyleConfig("com.puppycrawl.tools:checkstyle:${versions.checkstyle}") { transitive = false }
}
© www.soinside.com 2019 - 2024. All rights reserved.