-
Notifications
You must be signed in to change notification settings - Fork 306
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
Rule to restrict to specific bytecode java version #423
Comments
Unfortunately this is not possible at the moment, because nobody ever had a use case for it 🤔 It is easily possible to read the byte code version of the imported class AFAIS, but so far the info is simply ignored. |
Regarding the dependencies I agree these could be swapped out by clients. But i can’t control that of course. What i would like to do is protect myself from adding a dependency to my project that doesn’t meet the minimum bytecode requirement my project has. To give more background. I have an SDK that is used to access one of our REST APIs. That SDK has a requirement for java 7 or lower. I just had a bug in this project however because I updated a dependency version to the latest version. This is our usual process to update dependencies when working on a project. However, many java libraries do not make it easy to determine the bytecode they are compiled to. So i inadvertently added a dependency that uses java 8 when the previous version was java 7 even though I looked at the docs, I didn’t look hard enough though. This then broke one of the clients (in another project at the same company) that uses this SDK. I would love to write a test to protect myself from this. I fully understand this only will work if the project using my SDK doesn’t change this dependency version but we can’t solve all the problems. Although maybe I could shade to avoid this. That can be a discussion for another day perhaps. :) Thanks for the response. Have a great day! |
Would running your test suite with a JRE 7 catch such bugs? |
I also feel like the only way to really be sure it works with JRE 7 is to test it with JRE 7 🤔 That's by the way also what ArchUnit does itself 😉 Because sometimes even though the bytecode would be compatible there still is some incompatibility in implementation/behavior... |
I think running the tests with JRE 7 would catch these types of bugs for sure. What i don’t prefer though is now the developer and CI environment setups get more complex. It is becoming harder and harder to even get old JREs. I was hoping for a solution that allows me to install one JDK. Now with java 9+ and the ‘release’ flag it makes compiling to older versions much easier and less error prone. At the moment I install only java 11 but i can compile all the way back to 7. All this has made me wonder why the maven coordinates don’t support an option for specifying the bytecode version. 🤔 Although I believe that multi-version jars are a newish thing too when using java modules. |
So is there anything you could imagine adding to ArchUnit to help with my use case or do we just say I should really be testing with the target JRE I require? From my perspective, I would much prefer to just add a simple test case rather than configuring multiple JREs for tests (which is far more complex). But I understand if this use case is perhaps outside the goals of ArchUnit. |
I could well imagine to add this to ArchUnit (to know which version of byte code was imported seems to be just fair, if we also have things like the respective source file or even an MD5 sum of the imported class if activated). The entry point would be
And in fact AFAIS this first parameter |
Hi, I can't seem to determine how to accomplish my use case. Any help would be greatly appreciated.
Is it possible to verify that a jar I create is compiled to java 8 or below including all dependencies used by that jar?
I don't see anything in the API to check for bytecode version but I might just be missing it.
Thank you,
Peter
The text was updated successfully, but these errors were encountered: