-
Notifications
You must be signed in to change notification settings - Fork 8
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
Unable to resolve GlobalResource defined in a submodule/project #101
Comments
This comment was copied over from: disneystreaming/weaver-test#479 (comment) I'm sorry to say that's not something we can solve at the level of weaver. Weaver does not do any crawling through the classpath to retrieve global resource instances on its side, it's the build tool that is responsible for detecting the suites from the classes resulting from the compilation of the test scope, and then pass it to the test framework. I understand it's somewhat confusing, the relationship/delimitation between test framework and build tool is not obvious to the users. It's the exact same thing that causes the issue raised by your colleague there. Weaver is only responsible for telling the build tool "please look for classes extending this particular interface when you crawl through the test classpath", which happens here. You could most likely solve it at the level of the build tool (SBT), by setting something so that SBT would would look further than the immediate classes, but I'm afraid I'm not aware of how to do it. Maybe keynmol would be able to give pointers though, his knowledge of SBT is better than mine. |
This comment was copied over from: disneystreaming/weaver-test#479 (comment) Thank you for the quick reply. I'll investigate the SBT settings, and if I find anything, I'll report back and raise a PR to add a note to the GlobalResources docs. |
This comment was copied over from: disneystreaming/weaver-test#479 (comment) I understand what is happening a little better after investigating. When you call SBT test, it passes in all compiled classes from the project test folder as a Task for each item to Weaver. Weaver then looks at the task and decides what to do with that class, i.e. is it a GlobalResource, is it a suite etc. As Weaver relies on the GlobalResource detection from the passed in SBT task, it currently doesn't know about any GlobalResource instances on the classpath outside of the current SBT project. Looking a bit further, Weaver could use Java's SPI (Service Provider Interface) to detect additional GlobalResource's on the classpath. We can then merge the instances detected using SPI into the GlobalResources collected from SBT TaskDefs. In
Then in subprojects, the user/library owner creates the file Here are some docs on using Java SPI for reference https://docs.oracle.com/javase/tutorial/ext/basics/spi.html. It looks relatively simple from a library perspective to support, we call
I can look into it a bit further and put a PR together if it is something the project would consider. I have a hacked together version running locally that looks to work. |
This comment was copied over from: disneystreaming/weaver-test#479 (comment) I'd be willing to accept an SPI based solution that would complement the current state. I'm very familiar with the mechanism, and I think the idea has legs 😸 I'll be happy to review a PR :) |
This comment was copied over from: disneystreaming/weaver-test#479 (comment)
But you also like custom classloaders and various other dangerous things :P I've come to tentatively accept ServiceLoader approach because it's used in mdoc and it works there reasonably well. |
This comment was copied over from: disneystreaming/weaver-test#479 (comment) Any test framework that uses the SBT test interface has to deal with classloading, one way or another, it's not like we'd be stepping in a totally new danger zone. Also, SPIs are basically the standard solution for any plug-able architecture on JVM. For instance, compiler plugins in Scala are loaded via SPIs. It's just the most sane way to do this kind of thing. That being said, maybe rather than using Service loaders directly, the plugin mechanism could just read the metadata file (like ServiceLoader does) from JVM resources, and construct the correct fingerprint instance. |
This issue was copied over from: disneystreaming/weaver-test#479
It was opened by: aevanszen
If you define a GlobalResource in a subproject/module for re-use, i.e. a
test-support-module
, the GlobalResource cannot be resolved/used in a test in another module. You will get the below sample output:I have a sample project demonstrating this issue at https://github.com/aevanszen/weaver-global-resource-classloading-bug
It would be desirable to use GlobalResources defined in other subprojects/libraries for common code re-use.
A workaround is to define the GlobalResource as a trait in the shared project and then define an
object
extending the trait in the project you want to use the GlobalResource. This feels very much like a workaround, not desired functionality; for every project/subproject, you wish to re-use a common GlobalResource, you need to define a local class to the module by extending the shared trait.The text was updated successfully, but these errors were encountered: