-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CPD finds duplications in test fixtures despite source limitation #50
Comments
Hm, that sounds indeed very strange @C-Otto. Do you have a small reproducer? Is it urgent (just for my prioritization of things)? |
We won't be able to use CPD once we switched to Gradle, but that won't happen for a few weeks or so. Besides, we can live without CPD, although it's nice to have. So... not that urgent. I'll have a look at a reproducible case tomorrow. |
https://github.com/C-Otto/cpdtestfixtures If CPD is configured before the integration tests are introduced, for reasons I don't understand CPD also scans the integration test sources: If you enable the java-test-fixtures plugin in This might be related to gradle/gradle#13781 and the linked issues. |
Sounds like a lazy initialization stuff. Thanks for reproducer, I will have a look at it. |
Signed-off-by: Andreas Schmid <service@aaschmid.de>
Very, very strange ... but finally could find the problem: It appears if and only if the Here is the full story:
Example: if Good, that I have found the root cause of this issue. Bad, that I currently have only a quite ugly (gut feeling) hack to solve this. Concrete I check if the source was explicitly set and prevent further changes. @C-Otto does that information help you already such that you can fix the issue by restructuring your build? Another question to you @C-Otto: Also I prefer to apply the |
It looks like your IT adds a file with duplications to Anyway, for me the hotfix/hack using Running CPD on the whole project would be possible. This doesn't match the existing Maven configuration I'm using as a base, but I think that might be a valid step. However, the root project does not have any source, and I don't know how to configure CPD. If you have any ideas, I'd be happy to experiment further How to run CPD as part of
|
Depending on your needs, now java sourcesets of all projects will be automatically checked for duplicates (see Code. If you want to override this behaviour, you have a lot of options but note that the lazy evaluation of plugins applied to later configured subprojects adds further sourceSets again unless you use
or
or
or
Maybe I should document these as well ;-) Currently best idea for a proper solutions to this: I could provide an additional property with an allowlist or denylist for |
Thanks for the snippets, I'll try them out tomorrow. I agree, a bit more documentation wouldn't hurt, especially related to the warning I posted earlier (I've seen it several times when I tried to get the plugin to work with subprojects). The additional options also seem useful! |
I'm unable to create a configuration that combines the scan for all subprojects, as described in your response above. I'm using this snippet for all variants described below:
With this I get a single
With this I get the same (duplication in
Finally, I get
for
|
|
Sorry, I'm confused about the current state. Let's ignore the "global scan", i.e. using CPD to find duplicates between subprojects. My understanding: Is this correct? |
@C-Otto: sorry for the inactivity on this issue but my spare is quite limited at the moment and I honestly higher prioritize other things. I deeply need to think about the lazy initialization here but still not sure if this is really a bug... |
As long as CPD does not stick to the configuration, I'd like to think it's a bug. This could be a bug in the code that reads and applies the configuration, or something in the documentation. Either way, it does not work, and I have no way of making it work. |
I will try to figure out a solution as soon as possible using your reproducer from above. However, you mentioned |
I believe the issue is related to the existence of several source sets, and the name/purpose of these is not relevant. The reproducer contains two commits, where the initial commit exposes the bug with integration tests. |
I configured CPD for my multi-project Gradle 6.5.1 project. Some of these sub-projects make use of the java-test-fixtures plugin, which allows me to put Java files into
src/testFixtures/java
. Despite limiting thesource
as shown below, I get a CPD issue for code insidesrc/testFixtures/java
(both files which are part of the issue are inside the same directory).With
--debug
I see thetokenize
debug message for the files insource/main/java
, followed by those insource/testFixtures/java
:However, when I debug the
source
property in my configuration, everything is fine (i.e. I only seesrc/main/java
files):This happens with:
source = files('src/main/java')
source = sourceSets.main.java
source = sourceSets.main.allJava
The text was updated successfully, but these errors were encountered: