Skip to content
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

[Spring, Kotlin] Kotlin Metadata annotations breaks SpringFactory #1240

Closed
jensbaitingerbosch opened this issue Oct 6, 2017 · 4 comments · Fixed by #1246
Closed

[Spring, Kotlin] Kotlin Metadata annotations breaks SpringFactory #1240

jensbaitingerbosch opened this issue Oct 6, 2017 · 4 comments · Fixed by #1246
Labels
🧷 pinned Tells Stalebot not to close this issue
Milestone

Comments

@jensbaitingerbosch
Copy link

jensbaitingerbosch commented Oct 6, 2017

Summary

kotlin-spring does not work together with Kotlin Step classes

Expected Behavior

Given Two different Kotlin Steps definition classes like

@ContextConfiguration(classes = arrayOf(TestConfig::class))
class SomeSteps1 {
    // some step definitions
}

@ContextConfiguration(classes = arrayOf(TestConfig::class))
class SomeSteps2 {
    // some step definitions
}

When A scenario is executed using this step class as glue code
Then The scenario is executed without an error

Current Behavior

An exception is thrown:
cucumber.runtime.CucumberException: Annotations differs on glue classes found: com.xxx.SomeSteps1, com.xxx.SomeSteps2

Background: Kotlin adds an additonal Annotation kotlin.Metadata to each class. These Metadata differ for each class, therefore the check in SpringFactory.checkAnnotationsEqual() fails.

Possible Solution

Before comparing the annotations, remove annotations of type kotlin.Metadata (can be done by its name so there is no dependency to Kotlin)

Steps to Reproduce (for bugs)

(see above in Expected behaviour)

Context & Motivation

We use in our project Cucumber with Spring and Java for a while and I tried out to add a Kotlin step definition class, which did not work out that good...

Your Environment

  • Version used: 1.2.5
  • Operating System and version: Windows 10
  • Link to your project: -
@mpkorstanje mpkorstanje added the Bug label Oct 7, 2017
@mpkorstanje
Copy link
Contributor

The proposed solution works but over time has the potential to explode into a list of exceptions. This is undesirable. I think we should improve the solution to the underlying issue.

I'd have to study #711 to see if it would be possible to limit the number of step definition annotated with @ContextConfiguration to exactly one so we need not check for equality.

As a work around I'd either suggest manually ensuring there is only one step definition annotated by @ContextConfiguration or copying the SpringFactory and applying your solution locally. You can enforce factory selection by adding cucumber.api.java.ObjectFactory=package.of.MyFactory to cucumber.properties.

@brasmusson
Copy link
Contributor

@mpkorstanje It is absolutely possible to limit the number of glue classes annotated with @ContextConfiguraion (or @ContextHierarcy) to exactly one, in a sense that is the preferred usages after #711 (although that usage is not well documented). The only problem is that it is a non-backward compatible change. We could right not add a deprecation warning when more that one @ContextConfiguration glue class is found, and in the next major release start to fail on it.

@mpkorstanje
Copy link
Contributor

Deprecating it now and adding a ticket to the 3.0.0 mile stone should do it then.

@mpkorstanje mpkorstanje changed the title kotlin-spring does not work together with Kotlin Step classes [Spring, Kotlin] Kotlin Metadata annotations breaks SpringFactory Oct 11, 2017
@mpkorstanje mpkorstanje added this to the 3.0.0 milestone Oct 11, 2017
@aslakhellesoy aslakhellesoy added the 🧷 pinned Tells Stalebot not to close this issue label Oct 27, 2017
@lock
Copy link

lock bot commented Mar 9, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Mar 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🧷 pinned Tells Stalebot not to close this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants