aaschmid / gradle-cpd-plugin

Gradle plugin to find duplicate code using PMDs copy/paste detection (= CPD).
Apache License 2.0
95 stars 12 forks source link

Configuring CPDCheck as a seperate gradle file throwing below error #57

Closed RameshbabuJaga closed 3 months ago

RameshbabuJaga commented 3 years ago

My cpdcheck.gradle file like belo

            import de.aaschmid.gradle.plugins.cpd.Cpd

            apply plugin: "de.aaschmid.cpd"

            buildscript {
                repositories {
                    maven {
                        url "https://plugins.gradle.org/m2/"
                    }
                }
                dependencies {
                    classpath "de.aaschmid:gradle-cpd-plugin:3.2"
                }
            }

           // for source code cpd check (below task was running fine)
            cpd {
                language = 'java'
                toolVersion = '6.10.0'
                minimumTokenCount = 100 // approximately 5-10 lines
            }

            cpdCheck {
                reports {
                    text.enabled = true
                    xml.enabled = false
                }

                source = fileTree(dir: "$rootDir.absolutePath", includes: [
                        "app/src/main/java/**",
                        "utility/src/main/java/**",
                ])
            }

           // for test code cpd check -- (the error come from the below task) 
            task testCodeCpdCheck(type: Cpd) {
                skipLexicalErrors = false
                minimumTokenCount = 200
                language = 'java'
                pmdClasspath = fileTree('src/test/java')

                reports {
                    text.enabled = true
                    xml.enabled = false
                }
                source = fileTree('src/test/java')
            }

my build.gradle version: 4.0.2 Distributions gradle-6.1.1

aaschmid commented 3 years ago

Which gradle-cpd-plugin version do you use @RameshbabuJaga?

RameshbabuJaga commented 3 years ago

@aaschmid am using gradle-cpd-plugin:3.2

RameshbabuJaga commented 3 years ago

Basically, I want to configure the Source code and Test code with two different gradle files. So that I can manage duplicate codes based on the minimumTokenCount. For this, I am trying the above way.

aaschmid commented 3 years ago

Ah ok, if you look at the documentation on https://github.com/aaschmid/gradle-cpd-plugin#supported-versions, the v3.2 is no longer supported with Gradle < 6.6. Can your try to upgrade either Gradle or use gradle-cpd-plugin:3.1?

RameshbabuJaga commented 3 years ago

@aaschmid still same error

aaschmid commented 3 years ago

What have you tried? Both, upgrade Gradle and downgrade de.aaschmid.cpd?

Unfortunately, I have no further ideas yet. Therefore, I need to deeper investigate into that. Any further information would appreciated as I could not easily reproduce it ...

Edit: Working OSS examples: https://github.com/C-Otto/playground and https://github.com/TNG/junit-dataprovider.

RameshbabuJaga commented 3 years ago

I have tried to upgrade Gradle and downgrade de.aaschmid.cpd few versions.

aaschmid commented 3 years ago

Have you ever seen a working version or did you set it up from scratch? (I need further information in order reproduce it...)

RameshbabuJaga commented 3 years ago

@aaschmid I have started this myself from the scratch. Actually, I want to take this CPD part out of the app build gradle file. So I created cpdcheck.gradle file and pointed app build gradle like this

apply from: '../gradle-config/cpdcheck.gradle' afterEvaluate { assembleDebug.dependsOn cpdCheck }

Everything fine here. When I run cpdCheck on the source code it's working fine. Same way when I run the test code task testCodeCpdCheck

I am getting this error.

RameshbabuJaga commented 3 years ago

@aaschmid basically any idea how to create two different configurations for the Source and Test codes. So that I can manage easily at the time of each build.

aaschmid commented 3 years ago

@aaschmid I have started this myself from the scratch. Actually, I want to take this CPD part out of the app build gradle file.

Ah ok. It is working currently but no longer working after your refactoring, right?

@aaschmid basically any idea how to create two different configurations for the Source and Test codes. So that I can manage easily at the time of each build.

Now I got it. You want to have two Cpd tasks. You can create multiple cpd tasks by

  task anotherCpdTask(type: Cpd) {
    // config goes here
  }

with source being once subprojects*.sourceSets*.main*.java*.srcDirs (prod code) and once subprojects*.sourceSets*.test*.java*.srcDirs (test code)

(However, if you reuse the pre-configured cpdCheck task and configure and use it twice, does not explain the error message for me...)

RameshbabuJaga commented 3 years ago

@aaschmid Further I will look into it. But still, I have no idea from where that error popped up. As you saw that I have two different cpd checks with respect to the source. Still wondering about the error.

aaschmid commented 2 years ago

Any news on this @RameshbabuJaga ?

aaschmid commented 3 months ago

Closing due to no answers anymore, please feel free to reopen upon further information.