-
Notifications
You must be signed in to change notification settings - Fork 72
Classpath is duplicated in native tests with incompatible versions, preventing upgrade to newer JUnit versions #305
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
Comments
I'm almost certain that bug comes from this line: Lines 112 to 115 in 3cf0497
Here we unconditionally add JUnit version that is used in our support feature to the image building classpath. This is obviously wrong, but from my testing I found that if I don't specify this explicitly some of our tests fail as our classpath building code misses the JUnit dependency for some reason. @alvarosanchez can you take a look at this when you have time? |
So far it hasn't been much of an issue considering that the projects are working with somewhat the same junit version. You upgrade and the caller (for instance Spring Boot) upgrades as well. But the duplication looks strange, and the fact that we take the version of the plugin (and not the version of the project) is strange as well. Is there any plan to fix this? |
As mentioned in #541 (comment) and #706, users are currently forced to declare dependencies on all JUnit artifacts (or enough to pull in the rest transitively) if they want to use a newer version of JUnit 5 than the one hard coded into the NBT Maven plugin. Please note that Maven Surefire has automatic support for figuring out which compatible versions of JUnit 5 artifacts are actually required at test runtime (such as the On the other hand, Gradle now requires that users specify an explicit dependency on Similarly, I believe it's required (or at least recommended) to specify an explicit dependency on the For example, see: As stated in the JUnit 5 User Guide:
|
Maybe not for people 'in the know'. But it definitely harms Graal native adoption - for example we've been working on jdbi/jdbi#2476 since Aug 2023 to try to get Jdbi working with Graal native build pipeline, but keep running into issues like this that stop forward progress and still haven't completed the issue. (To be clear this issue is not the only one we ran into, but the 'death by multiple papercuts' effect where we keep running into rather inscrutable-to-the-end-user problems. At this point it seems like we know enough to apply a workaround, which I'll do next time I gather the energy to pick this PR up again...) Having inconsistent classpaths can cause really weird behavior that takes a long time to track down if you don't know where to start looking. We'd love to see this fixed :) |
Hey @stevenschlansker @snicoll @sbrannen, I made a pull request to fix this issue. It basically checks if there is already an artifact on the classpath with the same groupID and artifactID as the artifact we want to add (when adding JUnit artifacts). What I am wondering is if we can break existing projects if we fix this issue. Possible problem:
In that case we can catch and ignore The question is: can this fix harm existing projects if we suddenly remove "duplicates" (same artifacts but with different versions)? |
Thank you so much! At least from my perspective, the harm of having conflicting jars in the classpath far outweighs any harm caused by removing the duplicates - better to rip the bandage off and fix the root problem IMO. I believe the current stock OpenJDK implementation (not sure if this is guaranteed by spec?) will simply drop missing annotations from reflection metadata without further harm, which might simplify the case you're concerned about. |
According to this Stack Overflow answer by jarnbjo and section 13.5.8 of the current JLS:
|
Overview
When I run the
java-application-with-tests
locally I see that the classpath contains JUnit artifacts twice. In this particular case, they are the same versions.If I change the JUnit versions to 5.9.0/1.9.0, I then see this:
So, the 5.9.0/1.9.0 versions I declared actually get used, because they are first in the classpath, but we still should not include the 5.8.1/1.9.1 versions of JUnit artifacts in the classpath.
Note that this was tested with the Maven support. I did not verify if the same thing happens with the Gradle support.
Related Issues
JUnitPlatformFeature
unexpectedly failed with aJUnitException
#541The text was updated successfully, but these errors were encountered: