Conversation
ca7b8cf to
ddbb60c
Compare
When PMD execution is forked with using the toolchain selected JVM, then we can't access maven classes from maven4 due to UnsupportedClassVersionError. The classes PmdExecutor/CpdExecutor should only depend on classes of the maven-pmd-plugin or PMD, but not on maven. The exceptions have been replaced by the new PmdException, which is later on wrapped as MavenReportException or MojoExecutionException.
ddbb60c to
320a35a
Compare
|
So, this is really addressing a edge case here: Only when using maven4 (and you naturally run with java 17+ then) and want to analyze a java project, that uses e.g. java 8 or 11. In that case, you run into the problem with toolchains. The solution here makes the whole plugin a bit more fragile - and the logging also doesn't work anymore. Is it worth to support this edge case? With #726, the project can remove the toolchain plugin/configuration and PMD will run in the same JVM as maven (without forking) but still use the correct toolchain for type resolution. The current integration test (MPMD-304-toolchain-support) can be fixed easily by just using java 17 instead of 11... (see #736) @Bukama @slachiewicz What do you think? |
| // lead to a UnsupportedClassVersionError. | ||
| int majorJavaVersion = determineJavaVersion(javaExecutable); | ||
| if (majorJavaVersion < 17) { | ||
| classpath.removeIf(s -> s.contains("maven-logging")); |
There was a problem hiding this comment.
So, this will break the logging. The output will look like this:
[INFO] --- pmd:3.28.1-SNAPSHOT:pmd (pmd) @ auxclasspath-java-runtime ---
[INFO] PMD version: 7.27.0
[INFO] Toolchain in maven-pmd-plugin: JDK[/home/andreas/programs/openjdk/eclipse-temurin/jdk-8]
[WARNING] [stderr] SLF4J(W): No SLF4J providers were found.
[WARNING] [stderr] SLF4J(W): Defaulting to no-operation (NOP) logger implementation
[WARNING] [stderr] SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
And when running with -X, no logging from PMD itself is visible. So, not an optimal solution.
I think that there are still a lot of apps that target JDK 8, but I don't think that there are that much that will use such combination. My team builds on 17 but only compile against 8 - so no toolchain. However we get a lot of these auxClasspath warnings when building. A broken logging raises a "I dont like it" gut feeling. But as you can see by my words: Both are feelings, I don't have numbers. What about not supporting this edge case and wait until several users come up with such setup esp. as Maven 4 not out yet and we expect adoption will take some while? So I tend to not support this edge case. |
The auxClasspath warnings are addressed by #726 - but only if you have a matching toolchain in your toolchain.xml. You don't need to configure the toolchain-plugin, as otherwise, you'd run into exactly this issue (when using maven4).
Yes, let's skip this edge case for now until there is a real need. I'm closing this PR then. |
This is addressing an edge case: The combination of using maven-pmd-plugin with a toolchain < java 17 and running maven4:
When PMD execution is forked with using the toolchain selected JVM < java 17, then we can't access maven classes from maven4 due to UnsupportedClassVersionError.
The classes PmdExecutor/CpdExecutor should only depend on classes of the maven-pmd-plugin or PMD, but not on maven. The exceptions have been replaced by the new PmdException, which is later on wrapped as MavenReportException or MojoExecutionException.
This enables the IT "MPMD-304-toolchain-support" (it was skipped before due to no Oracle JDK in toolchains).
Following this checklist to help us incorporate your
contribution quickly and easily:
Note that commits might be squashed by a maintainer on merge.
This may not always be possible but is a best-practice.
mvn verifyto make sure basic checks pass.A more thorough check will be performed on your pull request automatically.
mvn -Prun-its 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.