Add kotlin code snippets to spring-boot refdoc
See spring-projectsgh-21778
Comment From: sdeleuze
FYI this PR is work in progress, more commits will come for other asciidoc files and I plan to review them.
Comment From: wilkinsona
Thanks for the PR, @IEnoobong. Before too much more time is invested in this, I think we should pause and consider https://github.com/spring-projects/spring-boot/issues/6313. That issue is already quite a big job and inlining Kotlin snippets in the documentation will make it bigger.
Comment From: sdeleuze
Hey @wilkinsona, would you be ok if we provide Kotlin code samples as runnable code directly?
I think providing a consistent experience across Boot and Framework reference documentation would bring a lot of value to developers (see how it looks like on here where core, testing, WebFlux and WebMvc documentations are translated).
Comment From: wilkinsona
That sounds good to me, assuming that we don't run into Eclipse-related problems with the Kotlin source. We've been fine with the Kotlin code that we've got thus far so I don't anticipate any problems.
A nice side-effect would be that it might give us the necessary impetus to do the same for our Java examples.
Comment From: sdeleuze
@IEnoobong After a second thought, I think you should use a Kotlin specific package but same class names.
So instead of:
package org.springframework.boot.docs.service
@Service
class KotlinDatabaseAccountServiceWithoutAutowired(private val riskAssessor: RiskAssessor) : AccountService {
//..
}
Something like:
package org.springframework.boot.docs.kotlin.service
@Service
class DatabaseAccountServiceWithoutAutowired(private val riskAssessor: RiskAssessor) : AccountService {
//..
}
Could you please modify the PR accordingly?
Comment From: IEnoobong
@sdeleuze Alright, I’m thinking to prefer service/kotlin to kotlin/service. What do you think?
Comment From: sdeleuze
That's ok
Comment From: IEnoobong
Please use immutable classes with
valproperties since they are now supported by Spring Boot 2.2 like:
data class BlogProperties(val title: String, val banner: Banner) { data class Banner(val title: String?, val content: String) }
Yes, there's an example on immutable binding on line 898
Comment From: IEnoobong
For configuration properties I make the objects
valbut the propertiesvar```kotlin class ImmutableAcmeProperties( var enabled: Boolean, var remoteAddress: InetAddress, var port: Int, val security = Security() ) {
class Security( var username: String?=null, var password: String?=null, @DefaultValue("USER") val roles: List
= mutableList() ) } ``` Aren't there runnable tests for the Java equivalent?
works with val too https://github.com/spring-projects/spring-boot/pull/18017#commitcomment-35075209
No there are not.
Comment From: sdeleuze
It will be too short for Spring Boot 2.2, I propose we target Spring Boot 2.3 for this PR instead (if possible beginning of the dev cycle in order to avoid too much merge conflicts). Maybe that will be also the opportunity to move forward on #6313 for Java as well in Spring Boot 2.3 timeframe if Boot team think it could be in the roadmap for next year.
Comment From: snicoll
A pre-requisite of this PR was that our code samples move first to code snippet so that we figure out what to do to provide a Kotlin counterpart. This PR has been sitting for a while and we'd like to to address the first part, see #6313.
Thanks for the PR and sorry for the wasted time.