diff --git a/docs/pages/pmd/userdocs/cli_reference.md b/docs/pages/pmd/userdocs/cli_reference.md index ba0353d144..19f5ad547e 100644 --- a/docs/pages/pmd/userdocs/cli_reference.md +++ b/docs/pages/pmd/userdocs/cli_reference.md @@ -194,6 +194,21 @@ Just set the environment variable `PMD_JAVA_OPTS` before executing PMD, e.g. windows="set \"PMD_JAVA_OPTS=--enable-preview\" pmd.bat check -d src\main\java\ -f text -R rulesets/java/quickstart.xml" %} +## Additional runtime classpath + +If you develop custom rules and package them as a jar file, you need to add it to PMD's runtime classpath. +You can either copy the jar file into the `lib/` subfolder alongside the other jar files, that are in PMD's +standard distribution. + +Or you can set the environment variable `CLASSPATH` before starting PMD, e.g. + +{% include cli_example.html + id="preview_classpath" + linux="export CLASSPATH=custom-rule-example.jar + pmd check -d ../../../src/main/java/ -f text -R myrule.xml" + windows="set CLASSPATH=custom-rule-example.jar + pmd.bat check -d ..\..\..\src\main\java\ -f text -R myrule.xml" %} + ## Exit Status Please note that if PMD detects any violations, it will exit with status 4 (since 5.3). diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index e917abee1b..55fc00125a 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -29,6 +29,8 @@ Being based on a proper Antlr grammar, CPD can: * honor [comment-based suppressions](pmd_userdocs_cpd.html#suppression) ### Fixed Issues +* core + * [#4395](https://github.com/pmd/pmd/issues/4395): \[core] Support environment variable CLASSPATH with pmd.bat under Windows * java-errorprone * [#4393](https://github.com/pmd/pmd/issues/4393): \[java] MissingStaticMethodInNonInstantiatableClass false-positive for Lombok's @UtilityClass for classes with non-private fields diff --git a/pmd-dist/src/main/resources/scripts/pmd.bat b/pmd-dist/src/main/resources/scripts/pmd.bat index 9c5b3cdf75..f7d3fe9474 100644 --- a/pmd-dist/src/main/resources/scripts/pmd.bat +++ b/pmd-dist/src/main/resources/scripts/pmd.bat @@ -63,10 +63,15 @@ if %_needjfxlib% EQU 1 ( ) :: The wildcard will include only jar files, but we need to access also :: property files such as javafx.properties that lay bare in the dir - set classpath=%TOPDIR%\conf;%TOPDIR%\lib\*;%JAVAFX_HOME%\lib\*;%JAVAFX_HOME%\lib\ + set pmd_classpath=%TOPDIR%\conf;%TOPDIR%\lib\*;%JAVAFX_HOME%\lib\*;%JAVAFX_HOME%\lib\ ) else ( - set classpath=%TOPDIR%\conf;%TOPDIR%\lib\* + set pmd_classpath=%TOPDIR%\conf;%TOPDIR%\lib\* ) +if [%CLASSPATH%] NEQ [] ( + set classpath=%CLASSPATH%;%pmd_classpath% +) else ( + set classpath=%pmd_classpath% +) -java %PMD_JAVA_OPTS% %jreopts% -classpath %classpath% %OPTS% %MAIN_CLASS% %* +java %PMD_JAVA_OPTS% %jreopts% -classpath %pmd_classpath% %OPTS% %MAIN_CLASS% %*