Question regarding Multi project support
damianoneill opened this issue · 10 comments
Hi, first off I'm not an expert on gradle so apologies if this is gradle specific rather than the plugin specific.
I have a multiproject that is structured as follows
src
├── build-tools
│ └── src
│ └── main
├── common
│ └── src
│ ├── main
│ └── test
├── gr
├── gradle
│ └── wrapper
└── services
├── bootstrap
│ └── src
├── device
├── operation
│ └── src
└── topology
src has my top level build.gradle, it does not include any code. The java projects exist below this level.
subprojects {
version = "2.0.0-SNAPSHOT"
repositories {
jcenter()
}
if (!it.name.startsWith('services')) {
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
...
Because the JavaBasePlugin exists in my subprojects only, I have configured your plugin as follows.
apply plugin: 'cpd'
plugins.withType(JavaBasePlugin) {
check.dependsOn(cpdCheck) // http://pmd.sourceforge.net/pmd-5.4.1/usage/cpd-usage.html#Suppression
}
cpd {
minimumTokenCount = 50 // default value
}
Note that check.dependsOn(cpdCheck) is not check.dependsOn(rootproject.cpdCheck) as rootproject in my case does not apply the java plugin.
When I do a gradle build of all projects from my top level directory it works perfectly.
However if I do only a subproject build for e.g. gradle :common:build I get the following warning.
WARNING: Due to the absence of JavaBasePlugin on project ':services:bootstrap' the task ':services:bootstrap:cpdCheck' could not be added to task graph and therefore will not be executed. SUGGESTION: add a dependency to task ':services:bootstrap:cpdCheck' manually to a subprojects 'check' task, e.g. to project ':common' using
check.dependsOn(':services:bootstrap:cpdCheck')
or to project ':services:bootstrap' using
project(':common') {
plugins.withType(JavaBasePlugin) { // <- just required if 'java' plugin is applied within subproject
check.dependsOn(cpdCheck)
}
}
Any help with this, would be much appreciated.
Thanks for the plugin, if I can get it working its will be fantastic value to the project.
Hi @damianoneill,
I have two questions:
- Does the CPD check gets executed if the
WARNING
appears? - Is it urgent as currently my spare time is rather rare ...?
Cheers,
Andreas
Hi Andreas, yes it does get executed. No rush, thanks.
Hi @damianoneill,
I could reproduce the issue somehow and could solve your problem by putting the
plugins.withType(JavaBasePlugin) {
check.dependsOn(cpdCheck) // http://pmd.sourceforge.net/pmd-5.4.1/usage/cpd-usage.html#Suppression
}
into
subprojects {
// ...
}
closure. The only thing I do not understand is how you get it running without the warning using gradle build
and how the CPD check execute for you at all.
If this does not solve your problem, I would like to ask your for a small reproducer including the settings.gradle
and maybe a short version of your build.gradle
. I am also happy to share my email address (incl. GPG key) if you do not like to post it here ...
Cheers,
Andreas
HI @damianoneill,
any news on this? Are you satisfied with the solution above or do you still have an issue?
Cheers,
Andreas
Hi Andreas, sorry for the delay. Unfortunately this didnt resolve the issue. To add to above its worth pointing out that I define the plugin in a separate file.
$ cat gr/cpd.gradle
apply plugin: 'cpd'
plugins.withType(JavaBasePlugin) {
check.dependsOn(cpdCheck) // http://pmd.sourceforge.net/pmd-5.4.1/usage/cpd-usage.html#Suppression
}
cpd {
minimumTokenCount = 50 // default value
}
and apply it from within the subprojects scope
subprojects {
...
apply plugin: 'java'
...
apply from: "$rootDir/gr/cpd.gradle"
...
Hi Andreas, pulled out a skeleton to replicate the issue. Attached.
$ gradle clean build
works
$ gradle :services:bootstrap:build
will show the issue
Hi @damianoneill,
thanks for the reproducer.
The problem is most likely how you apply the cpd plugin. I intended that is only applied once per project namely to the root project. Via source
attribute you can configure what projects should be checked. The benefit of doing this is that you can find duplicates across all sub projects. If this is ok for you, I can enhance the example you provided and you can check in your project.
If this is not an option for you, can you tell me what your project structure looks like and which projects should be checked separately for code duplicates?
Cheers,
Andreas
Thanks Andreas that approach will work fine. If you can enhance the example that would be great. Feel free to use the reproducer any way you want.
Hi @damianoneill,
I am not sure if all my changes work for you but with this patch applied to the reproducer I got it working as I would expect it:
0001-changes-required-to-get-it-working-for-all-projects.patch.txt
I am not sure about the skip_quality_check
...
Does that help?
Cheers,
Andreas
As there is no more response since a long time the issue might be fixed :-)
Otherwise don't hesitate to reopen it...