Skip to content

[java] Fix #5746: Separate test sources and resources#6619

Merged
adangel merged 6 commits into
pmd:mainfrom
UncleOwen:issue-5746-Separate-test-sources-and-resources
May 14, 2026
Merged

[java] Fix #5746: Separate test sources and resources#6619
adangel merged 6 commits into
pmd:mainfrom
UncleOwen:issue-5746-Separate-test-sources-and-resources

Conversation

@UncleOwen

Copy link
Copy Markdown
Member

Describe the PR

I rebased and updated @oowekyala's PR for #5746. All of the credits go to @oowekyala. This should enable us to add UnusedPrivateMethod (and possibly others) to https://github.com/pmd/build-tools/blob/main/src/main/resources/net/sourceforge/pmd/pmd-test-dogfood-config.xml.

I don't understand what is meant by "Update pom.xml to exclude generated-sources/... etc also for "pmd-test" execution (excludeRoots)" in the original PR. Could someone enlighten me?

Related issues

Ready?

  • Complete build ./mvnw clean verify passes (checked automatically by github actions)

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 1 complexity · 0 duplication

Metric Results
Complexity 1
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes. Give us feedback

@pmd-actions-helper

pmd-actions-helper Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Documentation Preview

No relevant source code has been changed, pmdtester skipped.

(comment created at 2026-05-10 12:42:18+00:00 for da69544)

oowekyala and others added 3 commits April 24, 2026 16:31
These suppressions weren't needed before the move,
they aren't needed after the move.
@UncleOwen UncleOwen force-pushed the issue-5746-Separate-test-sources-and-resources branch from 5bdd468 to e51c810 Compare April 24, 2026 14:37
@adangel adangel changed the title [java] Fix #5746: separate test sources and resources [java] Fix #5746: Separate test sources and resources May 8, 2026
@adangel

adangel commented May 8, 2026

Copy link
Copy Markdown
Member

Thanks for continuing this work.

I don't understand what is meant by "Update pom.xml to exclude generated-sources/... etc also for "pmd-test" execution (excludeRoots)" in the original PR. Could someone enlighten me?

This is about the configuration of the maven-pmd-plugin:

pmd/pom.xml

Lines 550 to 607 in 941fc0f

<executions>
<execution>
<id>pmd-main</id>
<phase>verify</phase>
<goals>
<goal>pmd</goal>
<goal>check</goal>
<goal>cpd</goal>
<goal>cpd-check</goal>
</goals>
<configuration>
<skip>${pmd.skip}</skip>
<minimumTokens>100</minimumTokens>
<rulesets>
<ruleset>/net/sourceforge/pmd/pmd-dogfood-config.xml</ruleset>
</rulesets>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/main/java</compileSourceRoot>
<compileSourceRoot>${project.basedir}/src/main/resources</compileSourceRoot>
</compileSourceRoots>
</configuration>
</execution>
<execution>
<id>pmd-test</id>
<phase>verify</phase>
<goals>
<goal>pmd</goal>
<goal>check</goal>
</goals>
<configuration>
<skip>${pmd.skip}</skip>
<targetDirectory>${project.build.directory}/pmdTest/</targetDirectory>
<includeTests>true</includeTests>
<rulesets>
<ruleset>/net/sourceforge/pmd/pmd-test-dogfood-config.xml</ruleset>
</rulesets>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/test/java</compileSourceRoot>
</compileSourceRoots>
</configuration>
</execution>
</executions>
<configuration>
<includes>
<include>**/*.java</include>
<include>**/*.xml</include>
</includes>
<linkXRef>false</linkXRef>
<targetJdk>1.${java.version}</targetJdk>
<skipPmdError>false</skipPmdError>
<failurePriority>2</failurePriority>
<failOnViolation>true</failOnViolation>
<printFailingErrors>true</printFailingErrors>
<!-- Skip the default pmd executions, which is triggered by pmd:check and avoid
unnecessary pmd analysis of the main code.
We use executions pmd-main and pmd-test instead and explicitly run pmd:pmd. -->
<skip>true</skip>
</configuration>

By default, m-pmd-p will use all compile source roots (see https://maven.apache.org/plugins/maven-pmd-plugin/pmd-mojo.html#compileSourceRoots) and test source roots ( https://maven.apache.org/plugins/maven-pmd-plugin/pmd-mojo.html#testSourceRoots ).
When you use the defaults, you can use https://maven.apache.org/plugins/maven-pmd-plugin/pmd-mojo.html#excludeRoots to remove some directory.
However, we already explicitly set the compile source roots, so we don't use an exclude. This is the case for the "pmd-main" execution.

Now, for the "pmd-test" execution: (Btw - we use different executions to have different rulesets for the tests classes) We now need to make sure, that we only analyze src/test/java and not src/test/java-resources . We might need to set includeTests=false - as otherwise all the test roots you added with build-helper-maven-plugin would be analyzed. I think, we added src/test/java as compileSourceRoot and not as testSourceRoot because m-pmd-p doesn't support to run on only on tests - it only support main or main+test combinations. So, we sell in the "pmd-test" execution main for test...

Since we are introducing "src/test/java-resources" now only for the pmd-java module and not for the others, we should probably leave the config in the parent-pom as is and adjust the config for pmd-java only:

pmd/pmd-java/pom.xml

Lines 130 to 135 in e7d8c88

<execution>
<id>pmd-main</id>
<configuration combine.children="append">
<excludeFromFailureFile>${project.basedir}/pmd-java-exclude-pmd.properties</excludeFromFailureFile>
</configuration>
</execution>

The problem, we want to solve with all this is: Can we now enable UnusedPrivateMethod in https://github.com/pmd/build-tools/blob/main/src/main/resources/net/sourceforge/pmd/pmd-test-dogfood-config.xml ? Did you try this? Does it work?

There are some other tasks on the original PRs:

  • Need to update checkstyle suppressions in build tools

Do we want to run checkstyle against src/test/java-resources?
Currently, checkstyle only excludes generated-sources. The configuration we have says, it should apply the rules to the test sources as well. So maybe we need to exclude src/test/java-resources?
I don't see, that we need to change the build-tools config for that (https://github.com/pmd/build-tools/blob/main/src/main/resources/net/sourceforge/pmd/pmd-checkstyle-suppressions.xml ) but only the java-specific override in pmd-java (https://github.com/pmd/pmd/blob/main/pmd-java/pmd-java-checkstyle-suppressions.xml )

Comment thread pmd-java/pom.xml Outdated
@adangel adangel added the needs:user-input Maintainers are waiting for feedback from author label May 8, 2026
@UncleOwen UncleOwen marked this pull request as draft May 9, 2026 15:36
UncleOwen added 3 commits May 9, 2026 18:46
The pmd-test config in the parent pom already defines src/test/java as
a regular (non-test) source. Setting includeTests to false excludes the
new src/test/java-resources directory.
@UncleOwen

Copy link
Copy Markdown
Member Author

I read somewhere that checkstyle is used to verify the license header. That part applies to src/test/java-resources as well.

Apart from that, I believe I have addressed all your comments. I tested with a locally installed version of build-tools, where I added

    <rule ref="category/java/bestpractices.xml/UnusedPrivateMethod">
        <priority>1</priority>
    </rule>

to pmd-test-dogfood-config. The build is green, and if I add a unused private method to one of the tests, the build turns red.

@UncleOwen UncleOwen marked this pull request as ready for review May 10, 2026 12:54

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment thread pmd-java/pom.xml
@adangel adangel added this to the 7.25.0 milestone May 14, 2026
@adangel adangel added in:pmd-internals Affects PMD's internals in:testing About tests of pmd, eg the module pmd-lang-test or pmd-test [test] and removed needs:user-input Maintainers are waiting for feedback from author labels May 14, 2026
adangel added a commit that referenced this pull request May 14, 2026
@adangel adangel merged commit dfae4b9 into pmd:main May 14, 2026
12 checks passed
@UncleOwen UncleOwen deleted the issue-5746-Separate-test-sources-and-resources branch May 14, 2026 14:27
@oowekyala

Copy link
Copy Markdown
Member

Thank you @UncleOwen and @adangel for bringing this to the finish line 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in:pmd-internals Affects PMD's internals in:testing About tests of pmd, eg the module pmd-lang-test or pmd-test [test]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java] Separate test sources and resources

3 participants