我正在尝试强制checkstyle插件使用存储在不同jar文件中的xml配置(作为依赖项)。
我创建了一个只包含该配置文件的软件包。
在build.gradle中,我有以下配置:
apply plugin: 'checkstyle'
checkstyle {
checkstyleMain {
classpath += configurations.checkstyleDep
}
checkstyleTest {
classpath += configurations.checkstyleDep
}
configFile = new File(getClass().getResource("/checkstyle.xml").toURI())
println(configFile)
}
configurations {
checkstyleDep
}
dependencies {
checkstyleDep "com.example:checkstyle-common:1.0"
}
不幸的是,这不会导致gradle看到依赖。
我的代码有什么问题?有更好的方法吗?
答案 0 :(得分:0)
考虑这种方法(5.0版):
# add the checkstyle plugin
plugins {
id "java"
id "checkstyle"
}
# load the dependency that has the rules
configurations {
checkstyleRules
}
dependencies {
checkstyleRules "com.github.ngeor:checkstyle-rules:3.3.0"
}
# configure checkstyle
checkstyle {
toolVersion "8.24"
config project.resources.text.fromArchiveEntry(configurations.checkstyleRules, "com/github/ngeor/checkstyle.xml")
}