Hello there!
I wrote some code for Kotlin 1.1.51 and it worked.
Basically the code implements a sample Kotlin RESTful service with Spring and Swagger2 in it. The working code can be seen at https://git.bitwell.fi/projects/SAM/repos/kotlin-spring-restful-webservice/browse
I cloned it out for maintenance, updated all deps to latest, including Kotlin to 1.2.30, and that does not build any more.
The failing file is as follows:
package fi.bitwell.poundam.service
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import springfox.documentation.builders.PathSelectors
import springfox.documentation.builders.RequestHandlerSelectors
import springfox.documentation.spi.DocumentationType
import springfox.documentation.spring.web.plugins.Docket
import springfox.documentation.swagger2.annotations.EnableSwagger2
@Configuration
@EnableSwagger2
open class SwaggerConfig {
@Bean
open fun api(): Docket = Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
}
}
Kotlin compiler says that "expecting a top level declaration. But if I move that fun to top level the @Bean
annotation or some other annotation is told to encompatible with a top level fun.
I’m clueless now what is wrong with that. Any ideas?