gradle-retrolambda
gradle-retrolambda copied to clipboard
Build ignores Kotlin changes with Retrolambda 3.1.0
Here's a test project: https://github.com/cypressious/KotlinRetrolambdaBug
Run the app. The activity should display "bar". Now go to com.cypressworks.kotlinretrolambdatest.Foo and change "bar to "foo". Run the app again. You will see "bar" again.
Gradle prints:
:app:compileDebugKotlin
:app:compileDebugJava UP-TO-DATE
:app:compileRetrolambdaDebug
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:preDexDebug UP-TO-DATE
:app:dexDebug UP-TO-DATE
:app:validateDebugSigning
:app:packageDebug UP-TO-DATE
:app:zipalignDebug UP-TO-DATE
:app:assembleDebug UP-TO-DATE
Notice how, despite compileDebugKotlin and compileRetrolambdaDebug being not up-to-date, the rest of the tasks was skipped?
When I make a change to a Java file, the tasks run correcty but the activity still prints the old value, meaning Kotlin changes are ignored.
Answer from a Kotlin dev: https://youtrack.jetbrains.com/issue/KT-7629
Experience the same problem (changes in Kotlin files not being reflected in compiled app).
My gradle output reads the same as yours (:app:compileDebugKotlin and : app:compileRetrolambdaDebug seem to run.
@cypressious Do you have found any workaround for this concrete issue?
Btw, it seems that the linked answer above is related to another ticket (https://github.com/evant/gradle-retrolambda/issues/106), not to this problem.
@sfunke I'm using gradle-retrolambda 3.0.1 and the workaround from https://github.com/evant/gradle-retrolambda/issues/106#issuecomment-97564105.
@evant Any progress on the underlying issue, though?
@cypressious Ah thanks, I see. I will give it a try.
@cypressious Unforntantly not, the latest version should've been more widely compatitble, but if it's still not working then more investigation needs to be done.
If anyone is interested, my workaround, based on @cypressious 's inspiration and my own limited gradle knowledge. (Just relates to debug build variant, but fits my needs very well.)
I am able to use latest retrolambda gradle plugin (3.2.0)
project.afterEvaluate {
def tasks = it.tasks
tasks.each {
// println "=== afterEvaluate: $it.name"
if(it.name == "compileDebugKotlin") {
it.doLast {
println "########"
println "Dynamically reset compileDebugJava's UP-TO-DATE flag"
println "########"
tasks["compileDebugJava"].outputs.upToDateWhen {false}
}
}
}
}
Explanation: As project is being evaluated, an execution block is added to the compileDebugKotlin task, so whenever that task is run (and our java classes are considered dirty), the compileDebugJava task's output upToDate-flag is set to false (so compileDebugJava is being forced to run).
Hacky and raw, but gets the job done.
Here's a version of @sfunke's workaround that's more generic (works with flavors) and possibly a bit faster:
project.afterEvaluate {
def variants = project.android.applicationVariants + project.android.testVariants
variants.each { var ->
def kotlinTask = tasks["compile${var.name.capitalize()}Kotlin"]
kotlinTask.doLast {
println "########"
println "Dynamically reset compile${var.name.capitalize()}Java's UP-TO-DATE flag"
println "########"
tasks["compile${var.name.capitalize()}Java"].outputs.upToDateWhen { false }
}
}
}
Seems to also work with JRebel for Android.
EDIT: In version 1.3.0 of the Android Gradle plugin, the task name seems to have changed to compile${var.name.capitalize()}JavaWithJavac.
If you get a chance, can you try with the android plugin 1.4.0-beta2 and the gradle retrolambda plugin 2.4.0-SNAPSHOT? I've changed it to use the new transform api which should remove the remainder of the task modifying weirdness.
Yeah, works alright. Am 20.09.2015 21:15 schrieb "Evan Tatarka" [email protected]:
If you get a chance, can you try with the android plugin 1.4.0-beta2 and the gradle retrolambda plugin 2.4.0-SNAPSHOT? I've changed it to use the new transform api which should remove the remainder of the task modifying weirdness.
— Reply to this email directly or view it on GitHub https://github.com/evant/gradle-retrolambda/issues/109#issuecomment-141822004 .
i made a gist out of @sfunke's and @cypressious's workaround https://gist.github.com/kibotu/fafd3047a46a7e838ab61a02804fb3ff
v 3.4.0 fixed this issue - can probably close this now