Reputation: 267
I have multi module gradle library project; no application module. I replicated this scenario by creating gradle init library project. The idea is to have convention plugin to handle cpd,pmd, spotBugs and other checks, and apply to each modules as necessary. The project structure is as follows
Root project 'multi-city'
+--- Project ':lib'
├── build.gradle
└── src
--- Project ':location'
├── build.gradle
└── src\
I have created the buildSrc folder in the root project as well. The rootProject has settings.gradle folder with the following content
rootProject.name = 'multi-city'
include('lib')
include 'location'
buildSrc/main/src/groovy/com.dilla.city.java-convention.gradle
plugins {
id 'java'
id 'de.aaschmid.cpd'
}
repositories {
mavenCentral()
}
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.
./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
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. 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
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. Is there a way to turn off the warning? or Is it ideal to do so?
Upvotes: 0
Views: 741
Reputation: 267
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
Upvotes: 0