-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Artifact transforms have incorrect current thread context classloader set and that affects java.xml.bind
implementation discovery
#29114
Comments
To have the essential information here too. When executing a task action, the thread context class loader gets set to the class loader of the task action that is executed. But for artifact transforms this thread context class loader setting is not done and the JAXB implementation is searched via the thread context class loader which then causes it not being found during the artifact transform. I guess that the thread context class loader should also be set for executing transform actions unless there is a reason not to. |
This issue needs a decision from the team responsible for that area. They have been informed. Response time may vary. One question to answer here is whether transforms implementations can have dependencies. |
Maybe I misunderstand, but why should they not? |
Yes, I think we should set a thread context classloader as suggested by @Vampire in that discussion. We should probably set it here here in the similar way as we do for tasks. A workaround for your problem is to do something like: public void transform(TransformOutputs outputs) {
File input = getInputArtifact().get().getAsFile();
File xrunArgsFile = outputs.file(input.getName() + ".xrun_args.f");
- DefaultHDVLCompileSpec compileSpec = getCompileSpec(input);
- writeXrunArgsFile(xrunArgsFile, compileSpec);
+ ClassLoader original = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ try {
+ DefaultHDVLCompileSpec compileSpec = getCompileSpec(input);
+ writeXrunArgsFile(xrunArgsFile, compileSpec);
+ } finally {
+ Thread.currentThread().setContextClassLoader(original);
+ }
} This change could have some different consequences so it needs more research. The issue is now in the backlog of the relevant team, but the existence of a workaround means it might take a while before a fix is made. |
java.xml.bind
in ArtifactTransformjava.xml.bind
implementation discovery
Current Behavior
I was trying to use
javax.xml.bind
in a plugin I’m developing. I see issues related to missing classes when I try to run in Java 11, but these only happen in a part of the code that uses JAXB and not in others.I'm running it on both Java 8 and Java 11. Since JAXB is not part of the JDK anymore from Java 9, I added a dependency in the plugin build:
I have two places in my plugin where I use JAXB. One place is in a task:
I can execute this task without any problems.
The other place where I use JAXB is in an artifact transform:
When the artifact transform gets executed, I get:
Expected Behavior
I would expect the dependency to be enough. I discussed this here in the Gradle forum with @Vampire and he suggested I open an issue.
Context (optional)
I switched to using a newer version of JAXB, which works on both Java 8 and 11 (version 3.0.2), but this required changing the namespace as well. I'm not blocked by the issue, but would like to understand whether I'm doing something wrong or whether something can be improved in Gradle.
Steps to Reproduce
I see the issue in this commit of my plugin: tudortimi/gradle-hdvl@3347a4e
To reproduce, after cloning that repo and selecting the commit, with Java 11 installed, run:
Gradle version
8.7
Build scan URL (optional)
https://scans.gradle.com/s/2micrd4yj3ahe
Your Environment (optional)
Java 11
The text was updated successfully, but these errors were encountered: