Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Support for kapt (for improved Kotlin support) #956

Closed
MichaelEvans opened this issue Oct 17, 2016 · 19 comments
Closed

Support for kapt (for improved Kotlin support) #956

MichaelEvans opened this issue Oct 17, 2016 · 19 comments

Comments

@MichaelEvans
Copy link

It was mentioned in #857 that kapt isn't supported. Opening this new issue to track support for it.

@kageiit
Copy link
Contributor

kageiit commented Oct 17, 2016

cc @dsyang

@kageiit
Copy link
Contributor

kageiit commented Dec 14, 2016

It seems like kapt3 in 1.0.6-eap77 ships with an APT_ONLY mode
https://github.com/JetBrains/kotlin/blob/8afac55a908c80feb7dd7bf7105e0557d34cacce/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/Kapt3Plugin.kt#L88
JetBrains/kotlin@95d1210

This means any build system can call kotlinc with this option and pass in kotlin source files to generate the java stubs required for the javac annoation processor round and compilation

facebook-github-bot pushed a commit that referenced this issue Jun 5, 2017
Summary:
Changes to support #1037, #956, and #395.
Closes #1283

Reviewed By: Coneko, dsyang

Pulled By: dsyang

fbshipit-source-id: f4ac981
@ZacSweers
Copy link
Contributor

Is there anything actually blocking this or does it just need someone to work on it now?

@runningcode
Copy link
Contributor

I don't think there's anything blocking it.
I filed this with the jetbrains team: https://youtrack.jetbrains.com/issue/KT-18072
Otherwise figuring out how to do this will require examining the source code of the gradle kapt plugin and seeing how it works.

I have some preliminary support for annotation processors in #1358. For example a kotlin class with an @Inject constructor seems to work fine when injected in to a java class. I haven't explored which parts of annotation processors aren't working.

@runningcode
Copy link
Contributor

runningcode commented Jun 16, 2017

I'll probably take a stab at this soon. I've been taking a look at how this is done in gradle land. This is how it is done in kotlin 1.1.3.

There's 4 steps.

  1. kaptGenerateStubsKotlin:
    run kotlinc with plugin:org.jetbrains.kotlin.kapt3:aptMode=stubs
  2. kaptKotlin
    run kotlinc with plugin:org.jetbrains.kotlin.kapt3:aptMode=apt
  3. compileKotlin
    run kotlinc regularly
  4. compileJava
    run javac with -proc:none and pass the generated sources from step 2.

These steps are slightly different with each minor version of kotlin so this will be interesting. It seems there are 3 steps in kotlin 1.1.2:

  1. kaptKotlin
    run kotlinc with plugin:org.jetbrains.kotlin.kapt3:aptOnly=true
  2. compileKotlin
    run kotlinc regularly
  3. compileJava
    run javac with -proc:none and pass the generated sources from step 1.

I figured these out by running a gradle build on a small kotlin module with --debug.

@cubuspl42
Copy link

For future reference: https://stackoverflow.com/questions/45217399/how-to-use-kapt-from-command-line-with-kotlinc

@elihart
Copy link

elihart commented Aug 4, 2017

@runningcode any progress on this? It would be awesome to be able to use kapt.

@cwoodwar6
Copy link
Contributor

@elihart It is still a work in progress. Hoping to have something together in the coming weeks.

@elihart
Copy link

elihart commented Aug 4, 2017

Great to hear :) Thanks!

@BharathMG
Copy link

Hi, Is there any progress in this feature? Currently, this is the only thing holding us back from using
buck in our android projects.

@cwoodwar6
Copy link
Contributor

@BharathMG sorry, progress has been slow. I haven't had much time to look at it. Step 1 outlined by @runningcode above seems to be failing even with the exact same arguments that Gradle uses. This leads me to believe there is some sort of Step 0 or my arguments are somehow incorrect. I haven't been able to prove either.

@BharathMG
Copy link

@cwoodwar6 Thanks for the update!

@yanex
Copy link

yanex commented Nov 16, 2017

@runningcode Hello :) Here is some additional information (I think you have already seen this though).

Please ping me if you want to know something more about kapt.

@thalescm
Copy link
Contributor

Hey folks, any news on this thread? Setting up buck in my company, but this is a blocker as of now, if I can do anything to help :)

@cwoodwar6
Copy link
Contributor

I haven't had very much time to look into this since I've posted the preliminary PR. Anyone who wants to pick up where I left off is more than welcome. I'm going to try my best to find time in the near future to work on it.

@felipecsl
Copy link

@thalescm sounds like you just volunteered 😄

@thalescm
Copy link
Contributor

Yeah, I've just forked buck and I'm reading the PR, getting the changes and stuff and will try to see if I get it working :D
I'll let you know if I get to anything before @cwoodwar6 does

@thalescm
Copy link
Contributor

If you guys can take a look on #1584. It should work now :)

facebook-github-bot pushed a commit that referenced this issue Mar 27, 2018
Summary:
This is still a major work in progress but I wanted to get the ball rolling. Currently this is building but fails at runtime to find the generated classes. I have only tested running it on an Android Project.

A huge shoutout to my former colleague runningcode who helped tremendously on this. #956 outlines the steps that he discovered when running kapt via Gradle.

I've created a simple [tool](https://github.com/cwoodwar6/kapt-cli) to better understand what steps are required when kapt is plugged into the compiler. I'll continue to update this PR and the tool as I make more progress. Feedback is welcome, looking for suggestions early so we can get this added as soon as possible.
Closes #1584

Reviewed By: jkeljo

Pulled By: jkeljo

fbshipit-source-id: 47a9598
@thalescm
Copy link
Contributor

Finally merged, I think it's safe to close the issue now. Please test it folks :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests