Gradle not seeing changes in Kotlin file


#1

Hi guys,

I’ve recnetly started converting part of my existing Android project to Koltin. I’ve added Kotlin source set, configured Gradle build file and installed Kotlin plugin. Everything works except one odd thing. Every time I make a change to a Kotlin file I have to clean the project in order for Gradle to pick up the changes. It is annoying. Kave you had similar problems? It seems it is specific to this project. When I make new project from the scratch it works. I’ve also tried to delete all Android Studio specific files and reimport the project and it is same…


#2

Hello! This looks like a bug with a mixed Java/Kotlin project in Kotlin Gradle plugin.

Firstly, some questions.

  1. What Kotlin Gradle plugin and Android Gradle plugin versions do you use?
  2. Do you use kotlin/ and java/ directories for the source code, or put everything into java/?
  3. Do you use kapt (Annotation processing for Kotlin)?

#3

1. I use latest version currently - 0.12.613. I started with 0.11.91 and have been updating it on regular base. I've had this problem with all of the versions. 2. I use separate directories, but I tried to use java only dir and it didn't help. 3. Nope, I use apt only. I need it for Dagger2, DBFlow and Butterknife. So module and db table definitions are still Java code and while I migrate some fragment to Kotlin I switch to Kotterknife instead of Butterknife...  


#4

I also had the same problem. The problem only occurs when using annotation.

To reproduce it is easy.

  1. Create multiple gradle module in 1 project.
  2. In one of the module, create something like:

class Sample {
  fun execute(str: String) {
  // …
  }
}

inline fun illegalInline(str: String, @inlineOptions(InlineOption.ONLY_LOCAL_RETURN) callback: Sample.() -> Unit) {
  Sample().execute(str)
}

  1. It will throws IllegalAccessError.
  2. Remove the annotations, and then Run.
  3. The exception is still thrown.
  4. Rebuild Project and then run. Exception’s gone.

This is quite serious bug. It will make you went crazy if you don’t realize that the problem is that you must rebuild your project everytime you use annotation.


#5

Could you provide a Gradle build logs (both for the incremental and clean builds) with the --debug key enabled ? You can send it to Yan.Zhulanow[at]jetbrains.com if you don't want to post it here.


#6

It seems that with all the latest stuff (gradle plugin, kotlin plugin, kotlin android) it works. Have you fixed it or it started to work in my project by itself? :)