adangel commented on code in PR #728:
URL: https://github.com/apache/maven-pmd-plugin/pull/728#discussion_r3977862766
##########
src/main/java/org/apache/maven/plugins/pmd/exec/Executor.java:
##########
@@ -29,37 +29,83 @@
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import org.codehaus.plexus.logging.console.ConsoleLogger;
+import org.codehaus.plexus.util.IOUtil;
abstract class Executor {
- protected static String buildClasspath() {
- StringBuilder classpath = new StringBuilder();
+ protected static String buildClasspath(String javaExecutable) {
+ List<String> classpath = new ArrayList<>();
// plugin classpath needs to come first
ClassLoader pluginClassloader = Executor.class.getClassLoader();
- buildClasspath(classpath, pluginClassloader);
+ classpath.addAll(buildClasspath(pluginClassloader));
ClassLoader coreClassloader = ConsoleLogger.class.getClassLoader();
- buildClasspath(classpath, coreClassloader);
+ classpath.addAll(buildClasspath(coreClassloader));
- return classpath.toString();
+ // Determine Java version: When running under maven4 and a toolchain
+ // selects a jdk < 17, then we need to exclude "maven-logging-x.jar"
from the
+ // classpath. Otherwise slf4j's Logging Factory will try to initialize
Maven4's
+ // service provider (org.apache.maven.slf4j.MavenServiceProvider)
which will
+ // lead to a UnsupportedClassVersionError.
+ int majorJavaVersion = determineJavaVersion(javaExecutable);
+ if (majorJavaVersion < 17) {
+ classpath.removeIf(s -> s.contains("maven-logging"));
Review 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.
--
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]