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
ClassCastException in Gradle build after upgrade to 6.3.0 #5275
Comments
Yes. Per a user request from a user migrating from the old Gradle In looking at the shadow plugin code it assumes the task's manifest object implements the shadow plugin's InheritManifest type as set in The ClassCastException occurs here: It would seem that a jar task cannot both be a bundle task and a shadow task since they both set the manifest to a custom implementation and shadow assumes the manifest object always implements its own There is not a great way to handle this as gradle does not have a means for a plugin/task to influence the effective manifest besides using a custom manifest implementation (and still using internal gradle types). I suppose one thing Bnd could do is inspect the type of the manifest object returned by diff --git a/gradle-plugins/biz.aQute.bnd.gradle/src/main/java/aQute/bnd/gradle/BundleTaskExtension.java b/gradle-plugins/biz.aQute.bnd.gradle/src/main/java/aQute/bnd/gradle/BundleTaskExtension.java
index a07b78b17..c35a16cc7 100644
--- a/gradle-plugins/biz.aQute.bnd.gradle/src/main/java/aQute/bnd/gradle/BundleTaskExtension.java
+++ b/gradle-plugins/biz.aQute.bnd.gradle/src/main/java/aQute/bnd/gradle/BundleTaskExtension.java
@@ -219,7 +219,10 @@ public class BundleTaskExtension {
// Wrap manifest
org.gradle.api.java.archives.Manifest manifest = task.getManifest();
effectiveManifest = new EffectiveManifest(manifest);
- if (manifest != null) {
+ // Only set manifest if no one else has set a custom implementation
+ if ((manifest != null) && manifest.getClass()
+ .getName()
+ .startsWith("org.gradle.")) {
task.setManifest(effectiveManifest);
}
Note: I don't test for |
Could the manifest be generated by a separate task or made available via an extension registered on the task instead? |
We use a proxy over all the interfaces of the existing manifest object so that if someone has set it to a custom type with custom interfaces, the custom interfaces will be preserved. See bndtools#5275 Signed-off-by: BJ Hargrave <bj@hargrave.dev>
The manifest is generated by the action of the BundleTaskExtension and only "lives" in the output jar file after the action completes. So I don't think a separate task makes sense. The effective manifest could be made available as a new output property from BundleTaskExtension. But I think the life cycle is a mismatch as the property value is not available at end of configuration time. It is only available at after task execution. I chose to use the task's effective manifest as that makes sense (since it is the actual effective manifest in the output jar) and also what users of the old Gradle I made a different solution, #5276, which uses proxies to support the custom interface used by shadow. When testing on your JUnit 5 |
We use a proxy over all the interfaces of the existing manifest object so that if someone has set it to a custom type with custom interfaces, the custom interfaces will be preserved. See bndtools#5275 Signed-off-by: BJ Hargrave <bj@hargrave.dev>
We use a proxy over all the interfaces of the existing manifest object so that if someone has set it to a custom type with custom interfaces, the custom interfaces will be preserved. See bndtools#5275 Signed-off-by: BJ Hargrave <bj@hargrave.dev>
Instead of setting a manifest object in the task so that we can set the effective manifest, after building we merge the generated manifest into the existing manifest object. Fixes bndtools#5275 Signed-off-by: BJ Hargrave <bj@hargrave.dev>
Rather than setting a manifest object in the task so that we can set the effective manifest after building, we instead merge the generated manifest into the existing manifest object. Fixes bndtools#5275 Signed-off-by: BJ Hargrave <bj@hargrave.dev>
Upon further thought, I completely redid the code to use the existing manifest merge support to merge the built manifest into the existing task manifest object. With the update, the fix now works on the |
Rather than setting a manifest object in the task so that we can set the effective manifest after building, we instead merge the generated manifest into the existing manifest object. Fixes bndtools#5275 Signed-off-by: BJ Hargrave <bj@hargrave.dev>
I marked this issue for a possible 6.3.1 release. |
Thanks for the quick turnaround! 👍 |
I tried updating the JUnit 5 build to 6.3.0 but it resulted in the following failure:
Stacktrace: https://ge.junit.org/s/jgs5agcbr2obq/failure#1
It looks like both the BND and the Shadow plugin replace manifest with their own implementation. Is that something that was introduced in 6.3.0?
The text was updated successfully, but these errors were encountered: