Affects PMD Version: at least > 6.0.0
Background: I currently migrate gradle-cpd-plugin using Gradle Worker API in order to avoid conflicts of different ANTLR versions and not pollute the default Gradle task execution classpath.
Description: Creating a Language
within a Gradle worker thread causes a java.util.ServiceConfigurationError: net.sourceforge.pmd.cpd.Language: Provider net.sourceforge.pmd.cpd.CPPLanguage not a subtype
exception. The reason is that the ServiceLoader
used in LanguageFactory
defaults to Thread.currentThread().getContextClassLoader()
to load classes. Gradle's Worker used a different classloader to load the class where LanguageFactory#createLanguage
is called from.
My Solution: I copied LanguageFactory
and replaced ServiceLoader.load(Language.class, this.getClass().getClassLoader())
(see de.aaschmid.gradle.plugins.cpd.internal.cpd.LanguageFactory). This is not a generic solution, however. Do you have other ideas on this or is it just an issue you are not willing to fix? I can try a PR if you give a rough direction how you would like to have it fixed.
Code Sample demonstrating the issue:
CpdAcceptanceTest#executing 'Cpd' task on duplicate 'java' source should throw 'GradleException' and produce 'cpdCheck.csv' with one warning
. Note that "cpdCheck.csv" is generated correctly (even if test might fail).LanguageFactory
and restore to ServiceLoader.load(Language.class)
. Now it fails with something like ServiceLoader<Language> languageLoader = ServiceLoader.load(Language.class); //, this.getClass().getClassLoader());
(Note: Don't hesitate to ask for a better branch / example. It is currently very WIP).
Running PMD through: [CPDs Java API] using Java 8 on Archlinux
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4