如何在多模块项目中排除Checkstyle中的一个模块。

huangapple go评论90阅读模式
英文:

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,您需要执行以下步骤:

  1. 在根项目中添加以下代码:
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'
    }
}
  1. 在子模块的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

  1. 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'
    	}
    }
  1. 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

huangapple
  • 本文由 发表于 2023年2月6日 02:16:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75354478.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定