Bukama commented on issue #291: URL: https://github.com/apache/maven-checkstyle-plugin/issues/291#issuecomment-7343518481
Following analyses and possible workaround suggestion was done by AI: --- I can still reproduce this on current master (3.6.1-SNAPSHOT). ### Reproduction I used a parent with two modules. `child-a` adds `gen/main/java` via `build-helper:add-source`, and the parent configures the `checkstyle-aggregate` report. | Invocation | Files in the aggregate result | |---|---| | `mvn clean compile site` | `B.java`, `Main.java` (**`Gen.java` is missing**) | | `mvn clean compile checkstyle:checkstyle-aggregate` | `B.java`, `Gen.java`, `Main.java` | ### Root cause The aggregate report collects its files from `getCompileSourceRoots()` of each reactor project ([`DefaultCheckstyleExecutor`](https://github.com/apache/maven-checkstyle-plugin/blob/master/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java)). With `mvn clean compile site`, Maven builds the reactor module by module, running all requested phases per module. The parent comes first, so its site (including the aggregate report) is generated **before** the child modules are built. At that point `build-helper:add-source` hasn't run in the children yet. Only the source directory from the POM model (`src/main/java`) is known, and any source roots added at build time are missing. When the aggregator goal is invoked directly on the command line, Maven runs it in a separate task segment after `compile` has finished for all modules. That's why the added source roots show up there. This also explains why configuring `<sourceDirectories>` doesn't help. In aggregate mode only the children's compile source roots are used. ### Workaround Invoke the aggregate goal directly after the build instead of relying on the site lifecycle: ``` mvn clean compile checkstyle:checkstyle-aggregate ``` ### Possible fix Other aggregating reports deal with this by forking the lifecycle: - `maven-javadoc-plugin` `aggregate` forks up to `compile` - `maven-pmd-plugin` `aggregate-pmd` forks up to `test-compile` Both also offer a `*-no-fork` variant. For this plugin, that would mean: 1. annotating `checkstyle-aggregate` with `@Execute(phase = LifecyclePhase.GENERATE_SOURCES)` 2. reading the source roots from `reactorProject.getExecutionProject()` (the forked project) instead of the original project I tried this as a quick prototype, and `Gen.java` is then included with `clean compile site`, `clean site` and `clean compile checkstyle:checkstyle-aggregate`. Trade-offs: - Every module runs up to `generate-sources` a second time, so expensive source generators would run twice. - It changes behavior for existing users, so a `checkstyle-aggregate-no-fork` goal without the fork should be added alongside it, as in the javadoc and PMD plugins. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
