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

Kotlin source generation #64

Closed
realdadfish opened this issue Feb 18, 2019 · 4 comments
Closed

Kotlin source generation #64

realdadfish opened this issue Feb 18, 2019 · 4 comments
Labels
enhancement New feature or request

Comments

@realdadfish
Copy link
Contributor

While Magnet itself is written in Kotlin, it outputs Java code, which is totally fine in general and perfectly interoperable with Java and Kotlin projects.
However, for Kotlin-only projects actually executing javac only once and even for very few files adds quite a bit time overhead, especially when there are many modules to compile.

It would be very cool if Magnet would get a Kotlin code generating processor so that overhead could be avoided.

@sergejsha
Copy link
Owner

sergejsha commented Feb 18, 2019

Correct me if I am mistaken, but as of now Android Gradle Plugin generates BuildConfig.java file anyway. Thus javac gets executed independent on whether magnet generates additional java sources or not.

Nevertheless I agree with you in general. I was thinking about this kind of optimization before and I am rather inclined to implementing a Kotlin compiler plugin. They speak about Kotlin IR (Intermediate representation), which can be used to represent source code independent of any particular source or target languages. It can be used to enhance/generate byte code directly bypassing java or kotlin sources. The idea was to "inject" static factories right in the implementation classes or so. But that's future if there is time for it...

@sergejsha sergejsha added the enhancement New feature or request label Feb 18, 2019
@realdadfish
Copy link
Contributor Author

Well, for my Kotlin-only modules I disabled BuildConfig.java generation altogether and got a nice speedup (partially from the generation itself, partially from the javac invocation), so it would definitely help I guess, but I have no exact numbers at hand.

If interested, this is how it is done:

 project.plugins.withId("com.android.library") {
        // TODO replace with https://issuetracker.google.com/issues/72050365 once released.
        project.android.libraryVariants.all {
            it.generateBuildConfig.enabled = false
        }
    }

Thanks for considering!

@sergejsha
Copy link
Owner

Yeah, I had this optimization too, but it stopped working with AGP 3.3.0. If you don't mind, I'm going to close this issue, because there is no plans for supporting kotlin source generation in the near future.

@realdadfish
Copy link
Contributor Author

Fine for me, I'll have a closer look at build times w/ Magnet enabled and report back here if I stumble upon any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants