maven-checkstyle-plugin icon indicating copy to clipboard operation
maven-checkstyle-plugin copied to clipboard

[MCHECKSTYLE-412] - Exclude generated sources / test-sources from defau…

Open gmshake opened this issue 2 years ago • 2 comments

…lt source / test-source directories

Following this checklist to help us incorporate your contribution quickly and easily:

  • [x] Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • [ ] Each commit in the pull request should have a meaningful subject line and body.
  • [ ] Format the pull request title like [MCHECKSTYLE-XXX] - Fixes bug in ApproximateQuantiles, where you replace MCHECKSTYLE-XXX with the appropriate JIRA issue. Best practice is to use the JIRA issue title in the pull request title and in the first line of the commit message.
  • [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • [x] Run mvn clean verify to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • [x] You have run the integration tests successfully (mvn -Prun-its clean verify).

If your pull request is about ~20 lines of code you don't need to sign an Individual Contributor License Agreement if you are unsure please ask on the developers list.

To make clear that you license your contribution under the Apache License Version 2.0, January 2004 you have to acknowledge this by using the following check-box.

gmshake avatar May 13 '22 07:05 gmshake

Does the effect not will be the same as we will use for default:

project.build.sourceDirectory
project.build.testSourceDirectory

without special filtering ...

slawekjaranowski avatar May 14 '22 18:05 slawekjaranowski

Does the effect not will be the same as we will use for default:

project.build.sourceDirectory
project.build.testSourceDirectory

without special filtering ...

Not exactly.

In my team we have many projects specify the sourceDirectories as we have JPA annotation processors and OpenAPI tools to generate REST API stubs. It is a burden we specify it now and then, so it will be perfectly that the default setting works OOB. I had tried to change sourceDirectories default to project.build.sourceDirectory but it breaks https://issues.apache.org/jira/browse/MCHECKSTYLE-70 as some users use build-helper-maven-plugin to inject source directories to the build. It looks that the best solution is excluding generated sources / test-sources from the build (project.compileSourceRoots / project.testCompileSourceRoots) before sending them to checkstyle.

It will be perfect that Maven core provide some API like getGeneratedCompileSourceRoots / getGeneratedTestCompileSourceRoots but apparently it will not go for 3.6.x and earlier versions (3.0.x, 3.3.x) . Since the generated sources / test-sources should be in build target directory we can bravely exclude the entire build target directory.

gmshake avatar May 16 '22 02:05 gmshake

What if I want to invert this and do check generated source?

michael-o avatar Apr 18 '23 14:04 michael-o

What if I want to invert this and do check generated source?

Well, this PR changes the default settings. You can still specify the sourceDirectories and testSourceDirectories, then checkstyle will check those directories.

gmshake avatar Apr 18 '23 15:04 gmshake

Anyone want to resolve conflicts and merge? This would be useful.

elharo avatar May 13 '23 11:05 elharo

Anyone want to resolve conflicts and merge? This would be useful.

I'll rebase it at this weekend.

I do not have write access to the Apache repository so I'll leave the merge to someone who's capable to do.

gmshake avatar May 19 '23 14:05 gmshake

  1. Rebased onto latest master
  2. Added a knob excludeGeneratedSources to not break existing setups, it is false by default

gmshake avatar May 22 '23 10:05 gmshake

@michael-o

Would be nice if this would have an IT showning the benefit.

Done !

gmshake avatar May 24 '23 10:05 gmshake

@michael-o

Would be nice if this would have an IT showning the benefit.

Done !

Testing...

michael-o avatar May 24 '23 11:05 michael-o

Thanks!

gmshake avatar May 24 '23 12:05 gmshake