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

Configure KAPT plugin when an annotation processor is selected #438

Open
leonard84 opened this issue May 26, 2017 · 11 comments

Comments

@leonard84
Copy link

commented May 26, 2017

The initializr should generate the appropriate entries for KAPT if the language is Kotlin and the ConfigurationProcessor is selected as dependency.

In gradle you just need to add the processor as an dependency to the kapt configuration:
dependencies { kapt "org.springframework.boot:spring-boot-configuration-processor" }
https://stackoverflow.com/questions/37858833/spring-configuration-metadata-json-file-is-not-generated-in-intellij-idea-for-ko

Maven is a bit more verbose https://kotlinlang.org/docs/reference/kapt.html and requires declaration of the kapt goal. However, there is an open issue that prevents kapt from working if a compiler plugin (e.g. kotlin-maven-allopen) is added as dependency https://youtrack.jetbrains.com/issue/KT-18022

@snicoll

This comment has been minimized.

Copy link
Contributor

commented May 29, 2017

@leonard84 start.spring.io doesn't know that entry is an annotation processor and I am not keen to bring that complexity at this point. I'd like to find another way to make it interoperable. Perhaps @sdeleuze knows?

@leonard84

This comment has been minimized.

Copy link
Author

commented May 29, 2017

@snicoll I just tested it, you actually don't need to define the spring-boot-configuration-processor inside the maven goal again. Just executing kapt is enough for it to be picked up, if it is already on the classpath. So the question is, whether to just always include the kapt goal, which would mimic normal javac behavior of executing the annotation processors, or add logic to only add the goal if an annotation processor is present.

I haven't found a simple way for gradle to omit the kapt configuration and have it run anyways. You can use configurations.kapt.extendsFrom(configurations.compileOnly) however I don't think that this is better than just declaring the kapt dependency.

@snicoll

This comment has been minimized.

Copy link
Contributor

commented May 30, 2017

I don't think that's the question. Annotation processors are automatically invoked with Java (it's part of the spec) so I'd rather have that with Koltin if we can. Implementing what you're asking means that initializr has to be aware that the dependency is in fact an annotation processor and I am not sure I like that idea.

@leonard84

This comment has been minimized.

Copy link
Author

commented May 30, 2017

@snicoll if you want it to behave similar to Java then you just need to declare the kapt execution for maven and extend the kapt configuration for gradle configurations.kapt.extendsFrom(configurations.compileOnly).

You already put annotation processors into a special scope compileOnly, that goes for spring-boot-configuration-processor as well as lombok. As far as I can see those are the only two depdendencies that are in that scope. So in a way you already know which dependency is an annotation processor.

@snicoll

This comment has been minimized.

Copy link
Contributor

commented May 30, 2017

I disagree that compileOnly means annotation processor actually. So no, I don't know those dependencies are annotation processors which brings me back to my first comment.

@sdeleuze

This comment has been minimized.

Copy link
Contributor

commented Jun 5, 2017

Kotlin requires an explicit plugin declaration for annotation processors support and it is unlikely to change, so I don't see a better solution than adding an optional boolean metadata like requireAnnotationProcessors on dependencies that requires it + add a language specifics support to add the relevant Maven/Gradle configuration.

@snicoll

This comment has been minimized.

Copy link
Contributor

commented Jun 5, 2017

@sdeleuze you are describing the current situation and I think it can be improved (especially when one claims 100% interoperability with Java). I've created https://youtrack.jetbrains.com/issue/KT-18289

@snicoll

This comment has been minimized.

Copy link
Contributor

commented Jul 21, 2017

My request has been declined so we'll need to make this work here.

@snicoll snicoll changed the title Add KAPT configuration for gradle/maven if Kotlin and ConfigurationProcessor is selected Configure KAPT plugin when an annotation processor is selected with Kotlin Jul 21, 2017

@snicoll snicoll added this to the 0.5.0 milestone Sep 15, 2017

@dima767

This comment has been minimized.

Copy link

commented Jan 15, 2018

Was anyone able to successfully use kapt to generate spring boot configuration metadata? I've created the simplest possible project with Gradle, but when I run build nothing happens. https://github.com/dima767/bootiful-kt-with-config-metadata-processing If someone could point me to a right direction that would be appreciated!

@snicoll snicoll modified the milestones: 0.5.0, 0.6.0 Feb 27, 2018

@snicoll snicoll changed the title Configure KAPT plugin when an annotation processor is selected with Kotlin Configure KAPT plugin when an annotation processor is selected Apr 17, 2018

@sdeleuze

This comment has been minimized.

Copy link
Contributor

commented Apr 24, 2018

@dima767 To generate Spring Boot configuration metadata, you should use var instead of val here. I will update Spring Boot reference documentation to mention that kapt should be used.

So it seems with #653, this issue will be straightforward to fix as suggested by @snicoll.

@sdeleuze

This comment has been minimized.

Copy link
Contributor

commented Feb 15, 2019

I have commented on KT-18022 to ask it to be reopened.

@snicoll snicoll added type: bug and removed type: enhancement labels Jul 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.