gradle-retrolambda icon indicating copy to clipboard operation
gradle-retrolambda copied to clipboard

Build ignores Kotlin changes with Retrolambda 3.1.0

Open cypressious opened this issue 10 years ago • 13 comments

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?

cypressious avatar May 06 '15 07:05 cypressious

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.

cypressious avatar May 06 '15 07:05 cypressious

Answer from a Kotlin dev: https://youtrack.jetbrains.com/issue/KT-7629

cypressious avatar May 06 '15 12:05 cypressious

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 avatar Jul 25 '15 09:07 sfunke

@sfunke I'm using gradle-retrolambda 3.0.1 and the workaround from https://github.com/evant/gradle-retrolambda/issues/106#issuecomment-97564105.

cypressious avatar Jul 25 '15 10:07 cypressious

@evant Any progress on the underlying issue, though?

cypressious avatar Jul 25 '15 10:07 cypressious

@cypressious Ah thanks, I see. I will give it a try.

sfunke avatar Jul 25 '15 14:07 sfunke

@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.

evant avatar Jul 25 '15 19:07 evant

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.

sfunke avatar Jul 27 '15 09:07 sfunke

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.

cypressious avatar Aug 21 '15 10:08 cypressious

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.

evant avatar Sep 20 '15 19:09 evant

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 .

cypressious avatar Sep 20 '15 20:09 cypressious

i made a gist out of @sfunke's and @cypressious's workaround https://gist.github.com/kibotu/fafd3047a46a7e838ab61a02804fb3ff

kibotu avatar Dec 09 '16 13:12 kibotu

v 3.4.0 fixed this issue - can probably close this now

sufeiiz avatar Jul 26 '17 20:07 sufeiiz