Skip to content

Commit

Permalink
Merge pull request #4395 from adangel:pmd6-support-env-CLASSPATH
Browse files Browse the repository at this point in the history
[core] Support environment variable CLASSPATH with pmd.bat under Windows #4395
  • Loading branch information
adangel committed Feb 23, 2023
2 parents 67c8daa + b5ea31d commit 2db7255
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
18 changes: 16 additions & 2 deletions docs/pages/pmd/userdocs/cli_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,22 @@ if you want to analyze a project, that uses one of OpenJDK's [Preview Language F

Just set the environment variable `PMD_JAVA_OPTS` before executing PMD, e.g.

export PMD_JAVA_OPTS="--enable-preview"
./run.sh pmd -d ../../../src/main/java/ -f text -R rulesets/java/quickstart.xml
```shell
export PMD_JAVA_OPTS="--enable-preview"
./run.sh pmd -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.

```shell
CLASSPATH=custom-rule-example.jar ./run.sh pmd -d ../../../src/main/java/ -f text -R myrule.xml
```

## Exit Status

Expand Down
2 changes: 2 additions & 0 deletions docs/pages/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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

Expand Down
7 changes: 6 additions & 1 deletion pmd-dist/src/main/resources/scripts/pmd.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
set TOPDIR="%~dp0.."
set OPTS=
set MAIN_CLASS=net.sourceforge.pmd.PMD
set PMD_CLASSPATH=%TOPDIR%\lib\*

java %PMD_JAVA_OPTS% -classpath %TOPDIR%\lib\* %OPTS% %MAIN_CLASS% %*
if [%CLASSPATH%] NEQ [] (
set PMD_CLASSPATH=%CLASSPATH%;%PMD_CLASSPATH%
)

java %PMD_JAVA_OPTS% -classpath %PMD_CLASSPATH% %OPTS% %MAIN_CLASS% %*

0 comments on commit 2db7255

Please sign in to comment.