简体   繁体   English

多模块gradle项目中的gradle cpd插件cpdCheck警告如何避免

[英]gradle cpd plugin cpdCheck warning in multi module gradle project how to avoid it

I have multi module gradle library project;我有多模块 gradle 库项目; no application module.没有应用程序模块。 I replicated this scenario by creating gradle init library project.我通过创建 gradle init 库项目复制了这个场景。 The idea is to have convention plugin to handle cpd,pmd, spotBugs and other checks, and apply to each modules as necessary.这个想法是让约定插件来处理 cpd、pmd、spotBugs 和其他检查,并根据需要应用于每个模块。 The project structure is as follows项目结构如下

Root project 'multi-city'根项目“多城市”
+--- Project ':lib' +--- 项目':lib'
├── build.gradle ├── build.gradle
└── src └── 源
--- Project ':location' --- 项目':位置'
├── build.gradle ├── build.gradle
└── src\ └── src\

I have created the buildSrc folder in the root project as well.我也在根项目中创建了 buildSrc 文件夹。 The rootProject has settings.gradle folder with the following content rootProject 有 settings.gradle 文件夹,内容如下

rootProject.name = 'multi-city'
include('lib')
include 'location'

buildSrc/main/src/groovy/com.dilla.city.java-convention.gradle buildSrc/main/src/groovy/com.dilla.city.java-convention.gradle

plugins {
    id 'java'
    id 'de.aaschmid.cpd'
}

repositories {
    mavenCentral()
}


buildSrc/build.gradle buildSrc/build.gradle

plugins {
    id 'groovy-gradle-plugin'
}

repositories {
    gradlePluginPortal()
}

dependencies {
    implementation 'de.aaschmid:gradle-cpd-plugin:3.1'
}

I added the convention plugin to one of the library,that is 'location'我将约定插件添加到库之一,即“位置”

location/build.gradle
plugins {
    id 'java'
    id 'com.dilla.city.java-convention'
}

cpd {
    ignoreFailures = true
}
tasks.withType(de.aaschmid.gradle.plugins.cpd.Cpd) {
    reports {
        xml.enabled = true
        text.enabled = false
    }
    source = files('src/main/java')
}

Under location/src/main/java I have created two java files to see if cpd is work as expected, and run the below command.在 location/src/main/java 下,我创建了两个 java 文件来查看 cpd 是否按预期工作,然后运行以下命令。 ./gradlew :location:clean :location:build

The issue is the following warning keep popping up.问题是以下警告不断弹出。 I have seen similar question raised on plugin forum, but the suggestions on the warning logs are not ideal for me.我在插件论坛上看到过类似的问题,但警告日志上的建议对我来说并不理想。 I want each module to use cpd individually I get the following error我希望每个模块单独使用 cpd 我收到以下错误

WARNING: Due to the absence of 'LifecycleBasePlugin' on project ':lib' the task ':cpdCheck' could not be added to task graph. Therefore CPD will not be executed. To prevent this, manually add a task dependency of ':cpdCheck' to a 'check' task of a subproject.
1) Directly to project ':location':
    check.dependsOn(':cpdCheck')
2) Indirectly, e.g. via project ':lib':
    project(':location') {
        plugins.withType(LifecycleBasePlugin) { // <- just required if 'java' plugin is applied within subproject
            check.dependsOn(cpdCheck)
        }
    }


> Task :location:cpdCheck
CPD found duplicate code. See the report at file:///home/da/Desktop/multi-city/location/build/reports/cpd/cpdCheck.xml

The first option did not work for me.第一个选项对我不起作用。 Then I copy pasted the second option in ':lib' module and it did make the warning disappear.然后我复制粘贴了':lib'模块中的第二个选项,它确实使警告消失了。 Now, if I want to run lib module like below ./gradlew :lib:clean :lib:build I get similar warning but now on the reverse, and suggest to add the following to ':location' module现在,如果我想像下面./gradlew :lib:clean :lib:build运行 lib 模块

   project(':lib') {
        plugins.withType(LifecycleBasePlugin) { // <- just required if 'java' plugin is    applied within subproject
            check.dependsOn(cpdCheck)
        }
    }

Now the more library projects I have the more snippet I add to remove these warning, but I do not want this approach.现在,我拥有的库项目越多,我添加的片段就越多以删除这些警告,但我不想要这种方法。 Is there way to do it?有办法吗? I am building the libraries individually and not sure why it trigger cpd check on the other modules.我正在单独构建这些库,但不确定它为什么会触发对其他模块的 cpd 检查。 Is there a way to turn off the warning?有没有办法关闭警告? or Is it ideal to do so?或者这样做是否理想?

I have missed the information that this issue has been identified as a bug .我错过了有关此问题已被确定为错误的信息。 I have just come across.我刚遇到。 I thought it was resolved issue我以为问题已解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM