-
Notifications
You must be signed in to change notification settings - Fork 468
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
Accessing Spring from custom extension: Change global extension execution order #817
Comments
releates #646 |
Thanks a lot for replying so quickly! Your are perfectly right in your comment in the pull request, sorry for wasting your time :-/ So as a result I took a step back, reconsidering what needs to be done. In my opinion the problem could be split into three more or less independent components:
I would like to suggest solving the first one and then moving on to the others 👍 Declaring dependencies of an extensionAs an extension developer I would like to declare dependencies on other extensions so these are loaded first (happens-before relationship). This has to be done before starting the extension and can be implemented
As far as I understand both mechanisms could be used on global and annotation driven extensions. P.S.: I'm also available on Gitter.im (gitter.im/tburny) if you prefer discussing this on the spock channel/via DM :) |
I'd like to avoid having to do a full dependency tree calculation for each test, for global extensions this is so much of an issue, but annotation based ones can vary for each test. I was thinking of using the simple ordering style (simple int), but that too has limitations. Only having dependencies might be a bit limiting, you can not express that you'd like to run before a certain extension. Ordering just the extensions might also be not enough, since extensions usually work by adding interceptors, which do the actual work. Normally you'd want to have a certain order going in (setup...) and the reverse order going out (cleanup...). So you actually want to order interceptors and not the extensions themselves. |
how to use this change "Fix #817" by using maven (1.3-groovy-2.x) |
Issue description
Currently global extensions are executed in the order they are discovered in the class path. That poses a problem when writing custom extensions which try to access fields in the Specification which will be initialized by Spring via
@Autowired
.When I have
MyGlobalExtension
inMyProject
, which depends onspock-spring
and last onspock-core
, the Spring extension will always add itsIMethodInterceptor
s afterMyGlobalExtension
.As far as I understand, there are a few possible workarounds (solutions) to the problem:
META-INF/services/org.spockframework.runtime.extension.IGlobalExtension
, so theglobalExtensionClasses
inGlobalExtensionRegistry
would probably become aLinkedHashSet<Class<?>>
. This would make the order of extensions configurable explicitly. (BUG: Currently the SpringExtension will be loaded twice if you do add it to your own extension configuration file)ExtensionRunner
:This ensures that all extensions in dependencies are loaded first, but would not fix the problem between extensions in different dependencies on the classpath
I will happily contribute a fix along with tests and a Gist if required :)
Java/JDK
java -version
1.7+
Groovy version
groovy -version
2.4
Build tool version
Gradle
gradle -version
Gradle wrapper from
spock-example
projectOperating System
Windows 10
IDE
IntelliJ
Build-tool dependencies used
Gradle/Grails
The text was updated successfully, but these errors were encountered: