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

Form class instrumentation is not run for Kotlin code #171

Closed
stephan-gh opened this issue Feb 9, 2017 · 10 comments
Closed

Form class instrumentation is not run for Kotlin code #171

stephan-gh opened this issue Feb 9, 2017 · 10 comments
Assignees
Milestone

Comments

@stephan-gh
Copy link
Contributor

stephan-gh commented Feb 9, 2017

Using gradle-intellij-plugin 0.2.0+ (I've tested 0.2.0 and 0.2.1), the form class instrumentation is not run for Kotlin code for me.

I've created a simple test project where I can reproduce the problem: https://github.com/Minecrell/intellij-test

It has a few Java, Groovy and Kotlin sources and a form component in the Kotlin source set: https://github.com/Minecrell/intellij-test/tree/master/src/main/kotlin/net/minecrell/test

To reproduce this problem I'm running gradle clean runIdea:

Using gradle-intellij-plugin 0.1.10 everything works correctly, however using 0.2.1 I get an error at runtime (which means that the form class instrumentation has not processed the Kotlin class):

Plugin 'net.minecrell.myplugin' failed to initialize and will be disabled.  Please restart IntelliJ IDEA.

kotlin.UninitializedPropertyAccessException: lateinit property panel has not been initialized
    at net.minecrell.test.TestComponent.<init>(TestComponent.kt:9)

In the Gradle log there is the following warning once for :compileJava and once for :compileGroovy (but not for :compileKotlin):

[ant:instrumentIdeaExtensions] /home/minecrell/dev/tmp/intellij-test/src/main/kotlin/net/minecrell/test/TestComponent.form: Class to bind does not exist: net.minecrell.test.TestComponent

Running gradle with the info flag suggests that it is not actually run for the Kotlin task:

Compiling forms and instrumenting code with nullability preconditions appears only twice in the log, after :compileJava and :compileGroovy but not after :compileKotlin.

@stephan-gh
Copy link
Contributor Author

I've taken a closer look at this. The root issue seems to be that gradle-intellij-plugin configures the instrumentation action for all AbstractCompile tasks the classes task depends on. However, it doesn't seem like the classes task does actually have a dependency on compileKotlin. Printing the dependencies reports the followiing:

[task ':compileJava', task ':processResources', task ':compileGroovy']

It works when I add a dependency on compileKotlin manually for the classes task:

tasks.classes.dependsOn 'compileKotlin'

@zolotov
Copy link
Member

zolotov commented Feb 13, 2017

Hi @Minecrell,

Thank you for investigation. The fix will appear in 0.2.2 tomorrow.

Nevertheless, it's not recommended to use form designer with kotlin. It doesn't work properly anyway. Please consider using layout.kt instead.

@zolotov zolotov self-assigned this Feb 13, 2017
@zolotov zolotov added this to the 0.2.2 milestone Feb 13, 2017
@zolotov zolotov closed this as completed Feb 13, 2017
@stephan-gh
Copy link
Contributor Author

Hi @zolotov,

Thank you for the fix. It works now, but only if the Kotlin Gradle plugin is applied before gradle-intellij-plugin. If gradle-intellij-plugin is applied first then it will fail to detect the compileKotlin task. I guess this is because the Kotlin Gradle plugin registers the dependency in afterEvaluate, so if gradle-intellij-plugin is applied first, its afterEvaluate is called before Kotlin registers the dependency.

This change fixes it for my test project: https://github.com/Minecrell/intellij-test/commit/7539c4be67c2c9492aa7f61ec29b583bef25a89e It doesn't work if it's applied as part of the plugins block.

@zolotov
Copy link
Member

zolotov commented Feb 14, 2017

Thank you for the fix. It works now, but only if the Kotlin Gradle plugin is applied before gradle-intellij-plugin

Yes, I noticed this too and I didn't think of something that I can do with this, sorry

@stephan-gh
Copy link
Contributor Author

@zolotov Do you really need to check if they are one of the dependencies of the classes task? A simple tasks.withType(AbstractCompile) would run for all AbstractCompile tasks.

@stephan-gh
Copy link
Contributor Author

Nevermind, I just saw 63f0780

@zolotov
Copy link
Member

zolotov commented Feb 14, 2017

@Minecrell I'm not sure about 63f0780. Maybe this fix also breaks that commit. Feel free to investigate this and make a PR.

@zolotov
Copy link
Member

zolotov commented Feb 14, 2017

Looks like I have to revert the change. Resolving transitive dependencies of compile tasks leads to evaluating nested projects which weren't evaluated yet. And this breaks multi-module projects.

So, I'm afraid you have to add compileKotlin <- classes dependency after all :(

@zolotov
Copy link
Member

zolotov commented Feb 14, 2017

Not sure how to fix it on the side of gradle-intellij-plugin. For history:

@stephan-gh
Copy link
Contributor Author

stephan-gh commented Feb 14, 2017

@zolotov I've actually run into an error like #77 today so I'm pretty sure this is broken again since #116. (And it's not actually related to the instrumentation of Kotlin classes, it happened for a Java class.) In any case, I'm not sure if there is a simple solution:

On the one hand we need to instrument the classes as part of the actual compile task using doLast, otherwise Gradle will detect changes to the output files and recompile everything.
On the other hand the class instrumentation requires some of the compiled classes (potentially from another compile task) in some cases which means we would have to run it after all compile tasks have already run.

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

No branches or pull requests

2 participants