我似乎偶然发现了一个非常简单的问题(应该非常简单),但在过去 4 小时内找不到答案。
我正在尝试从已导入到我的项目中的依赖项 (JAR) 在我的 gradle 项目中配置自定义 checkstyle 配置。依赖项已从我们的内部 nexus maven 存储库中成功提取(我可以在 IntelliJ 中的外部库下看到文件)。
这是我的
build.gradle
:
plugins {
id 'checkstyle'
}
repositories {
mavenCentral()
maven {
url = uri('https://repository..../repository/maven-releases')
}
}
dependencies {
implementation("tech.qa:UICheckstyle:1.0.8")
}
我已确保 checkstyle 在
config/checkstyle/checkstyle.xml
存储库内的 UIcheckstyle
(默认位置)下可用。
这是我尝试过的一切:
gradle build
时,出现以下错误:Execution failed for task ':checkstyleMain'.
> A failure occurred while executing org.gradle.api.plugins.quality.internal.CheckstyleAction
> An unexpected error occurred configuring and executing Checkstyle.
> Unable to create Root Module: config {/Users/arjunvijayakumar/Desktop/workspaces/ui-automation/config/checkstyle/checkstyle.xml}, classpath {null}.
dependencies {
checkstyle("tech.qa:UICheckstyle:1.0.8")
}
错误是:
Execution failed for task ':checkstyleMain'.
> A failure occurred while executing org.gradle.api.plugins.quality.internal.CheckstyleAction
> java.lang.ClassNotFoundException: com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask
checkstyle
块:checkstyle {
configFile = rootProject.file("config/configuration/checkstyle.xml")
// This is obviously wrong. I am not sure how to access the file inside the JAR
}
我是否必须沿着 this 路径才能通过
ClassLoader
访问文件。听起来很原始,我觉得必须有一种更简单的方法。
请告诉我是否有人可以帮助我?
提前致谢。
将配置文件打包为 Zip 存档并将其发布到组织的 Maven 或 Ivy 存储库。对于以下示例,我们假设存档已发布到 https://mavenrepo.mycompany.com,标识符为 mycompany.com:checkstyle-config:1.0。
apply plugin: "java"
apply plugin: "checkstyle"
repositories {
maven {
url "https://mavenrepo.mycompany.com"
}
}
configurations {
checkstyleConfig
}
dependencies {
checkstyleConfig "mycompany.com:checkstyle-config:+@zip"
}
checkstyle {
config = resources.text.fromArchiveEntry(
configurations.checkstyleConfig, "checkstyle-config.xml")
}