Comments (16)
The plugin to generate the module-info works as expected, but indeed, ASM does not reproduce the packages that are provided to it when reading the generated module-info. I will look into it!
from byte-buddy.
It seems like the ModulePackages
attribute disappears somewhere during jar file packaging. It is generated correctly. But if I unzip the jar and check the contained module-info
, it seems to disappear.
from byte-buddy.
This seems to be related to the "jar" tool. With Java 8, everything works. The module-info
class file is simply included as is. With Java 17 or 21, the ModulePackages
attribute is removed.
from byte-buddy.
I did test the module-info.class
file myself and indeed running javap module-info.class
returned the text representation of that file, so the file itself is probably ok.
Something must be wrong in some of the jar headers?
from byte-buddy.
This seems to be related to the "jar" tool. With Java 8, everything works. The module-info
class file is simply included as is. With Java 17 or 21, the ModulePackages
attribute is removed by the "jar" tool. All other attributes remain intact.
I find this behaviour rather surprising but I assume that I need to specify something on the command line. I will investigate.
from byte-buddy.
Turns out that the jar tool processes the package attribute of a module-info when placing it in a jar and removes all packages that are not contained. This breaks here since the shade plugin is adding class files later from a different location which is not present when the jar is first assembled. As a result, the module-info is incomplete. This does of course not happen with Java 8 as it is not aware of the module-info.
Strange feature of the jar tool, I say, but I worked around it by injecting the module-info class into the jar file now after the jar tool is used. I had to make some tweaks to the (my) plugin to support reproducible builds what did not work before, but this works now.
from byte-buddy.
Can you try master now?
from byte-buddy.
Turns out that the jar tool processes the package attribute of a module-info when placing it in a jar and removes all packages that are not contained. This breaks here since the shade plugin is adding class files later from a different location which is not present when the jar is first assembled. As a result, the module-info is incomplete. This does of course not happen with Java 8 as it is not aware of the module-info.
Strange feature of the jar tool, I say, but I worked around it by injecting the module-info class into the jar file now after the jar tool is used. I had to make some tweaks to the (my) plugin to support reproducible builds what did not work before, but this works now.
Simple check worked for me, I didn't check the initial failure (byte-buddy couldn't be used as a modular dependency when bootstrapping Maven with JDK 21, that takes some time to do).
Maven Jar plugin uses the default lifecycle phase package and I don't see a proper phase for modulemaker in this list after that, but initially I was in favor of changing the default lifecycle of the modulemaker so that it would be executed after Jar.
But it probably doesn't make sense.
from byte-buddy.
Do you have an idea why this problem manifests with JDK 21? I can only think of natural code changes to the jar
tool. I don't see any other reason for it.
from byte-buddy.
Java 17 does not validate this aspect of a module info. Seems like that code was introduced in Java 20 and not backported.
from byte-buddy.
With the backported changes to modulemaker and byte-buddy I was able to bootstrap Maven.
I am not sure if the fix in modulemake is "clean" or rather a workaround but it works for now, so this issue can be closed.
By the way, have you considered using a more standard approach to adding a module-info.class
to your jars other than using your own Maven plugin? There are dozens of projects facing the same issue of adding it to their projects while remaining compatible with older versions of Java. I don't know if this project has any other special requirements.
from byte-buddy.
When I added the plugin there was nothing really, but I am happy to revisit. Do you know of a good option? I do however wonder if they work with the shade plugin then.
from byte-buddy.
Ah right, shade plugin, i don't really know what it does, we always remove it from our packages before our builds.
All I know is it renames class/package names.
from byte-buddy.
And repackages. ASM did some major. API changes in the past, thus the repackaging.
from byte-buddy.
So, first thing that comes to my mind is to have a module-info.java
plus a two-step compilation in the pom where the first step compiles everything except the module info and the second step compiles the module info only, similar to this:
https://github.com/mizdebsk/java-deptools-native/blob/master/pom.xml#L101
from byte-buddy.
The problem being is that I want to create the same jar with all toolchains from Java 6 upwards. With my plugin this is possible, but but I did not find other ways of doing it.
from byte-buddy.
Related Issues (20)
- How to apply Byte Buddy plugin placed under /src/test? HOT 13
- I am sorry, this is a question about java bytecode HOT 5
- Not able to intercept methods of java.net.HttpURLConnection class in Java 17 HOT 1
- Strange interaction with method implementations for methods from composite interfaces HOT 1
- Replace Method Code HOT 3
- Can I replace the new byte[] in the onTransformation method? HOT 1
- I want to use bytebuddy to advice java.time.LocalDateTime HOT 3
- BUG: instrumentation error HOT 3
- No classes have been predefined during the image build to load from bytecodes at runtime HOT 8
- Verify Error on Byte Buddy generated class HOT 1
- Question: copy class hierarchy in an environment without Java Agent HOT 1
- Can 'private final method' in 'public final class' be redefined? HOT 4
- Method matchers works by chance HOT 2
- Why does ClassNotFoundException appear in Interceptor when running in SpringBoot? HOT 1
- Compilation error after adding lombok to classpath HOT 1
- why is the byte-buudy AgentBuilder source code so long ? HOT 2
- matched class wasn't transformered and the issue appears just twice, and i didn't reproducing the issue HOT 10
- Fail to read property due to `IllegalArgumentException` when using it on withX methods HOT 4
- Improve diagnostics/troubleshooting features for agent installation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from byte-buddy.