英文:
How to exclude a module for checkstyle in a multi-module project
问题
我有一个多模块复合构建项目。
项目结构如下:
Panda. // 根项目
-PandaService. // 服务模块
-PandaDataAccessLayer // 使用JOOQ自动生成的DAL模块
我想要在checkstyle中排除PandaDataAccessLayer
模块,因为它的代码是由JOOQ自动生成的。
我的checkstyle.xml位于Panda/config/checkstyle/checkstyle.xml
,以下是我根项目Panda
中的build.gradle
文件:
repositories {
mavenCentral() // 使用Maven Central来解析依赖项。
}
subprojects {
apply plugin: 'java'
apply plugin: 'checkstyle'
checkstyle {
toolVersion = '10.7.0'
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
checkstyleMain.exclude '**/PandaDataAccessLayer/**'
}
sourceCompatibility = '11'
targetCompatibility = '11'
}
我可以看到checkstyle正在运行./gradlew build
。但生成的报告仍然显示它在PandaDataAccessLayer
模块中检查代码。
找到Checkstyle规则违规。请查看报告:file:///****/panda/PandaDataAccessLayer/build/reports/checkstyle/main.html
如何完全排除PandaDataAccessLayer
模块以使其不受checkstyle检查?
1: https://docs.gradle.org/current/userguide/composite_builds.html
2: https://checkstyle.sourceforge.io/
英文:
I have a multi-module composite build project.
The project structure is this:
Panda. // Root project
-PandaService. // Service module
-PandaDataAccessLayer // DAL module whose code are generated with JOOQ
I want to exclude PandaDataAccessLayer
module for checkstyle, because its code are generated automatically with JOOQ.
My checkstyle.xml is located at Panda/config/checkstyle/checkstyle.xml
, and here is the build.gradle
in my root project Panda
:
repositories {
mavenCentral() // Use Maven Central for resolving dependencies.
}
subprojects {
apply plugin: 'java'
apply plugin: 'checkstyle'
checkstyle {
toolVersion = '10.7.0'
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
checkstyleMain.exclude '**/PandaDataAccessLayer/**'
}
sourceCompatibility = '11'
targetCompatibility = '11'
}
I can see that checkstyle is running with ./gradlew build
. However, the generated report still shows that it checks code in PandaDataAccessLayer
module.
> Checkstyle rule violations were found. See the report at:file:///****/panda/PandaDataAccessLayer/build/reports/checkstyle/main.html
How can I exclude the PandaDataAccessLayer
completely from checkstyle?
答案1
得分: 2
为了在rootProject/main项目和所有子模块中激活Checkstyle,您需要执行以下步骤:
- 在根项目中添加以下代码:
allprojects {
apply plugin: 'java'
checkstyle {
toolVersion = '10.6.0'
configFile = file("${rootDir}/config/checkstyle/checkstyle_google_customized.xml")
ignoreFailures = false
maxWarnings = 0
}
checkstyleMain {
source = 'src/main/java'
}
checkstyleTest {
source = 'src/test/java'
}
}
- 在子模块的gradle文件中添加以下代码:
plugins {
id 'java'
id 'checkstyle'
}
checkstyle {
toolVersion = '10.6.0'
configFile = file("${rootDir}/config/checkstyle/checkstyle_google_customized.xml")
ignoreFailures = false
maxWarnings = 0
}
如果要排除某个子模块,只需排除第二步,系统将仅考虑主项目。
英文:
To activate checkstyle in the rootProject/main project and all the sub modules then you have to do the following steps
- In the root project add
allprojects {
apply plugin: 'java'
checkstyle {
toolVersion = '10.6.0'
configFile = file("${rootDir}/config/checkstyle/checkstyle_google_customized.xml")
ignoreFailures = false
maxWarnings = 0
}
checkstyleMain {
source = 'src/main/java'
}
checkstyleTest {
source = 'src/test/java'
}
}
- In a submodule's gradle file
plugins {
id 'java'
id 'checkstyle'
}
checkstyle {
toolVersion = '10.6.0'
configFile = file("${rootDir}/config/checkstyle/checkstyle_google_customized.xml")
ignoreFailures = false
maxWarnings = 0
}
If you exclude a submodule then only exclude step two and it will only consider the main project
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论