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

how to configure the plugin to apply on a specific directory of classes?

Open aminabs opened this issue 9 years ago • 1 comments

Hi, I want to know if there is a way to configure input directory for the retrolambda plugin. It seems to me its not configurable since I can't see any info about it on the home page. To elaborate, please take a look at the retrolambda maven plugin here where you see an option 'retrolambda.inputDir' available for doing so.

aminabs avatar Apr 10 '16 10:04 aminabs

I had this exact same issue (I wanted to use libraries which are compiled with Java 8) and I have solved this by making the retrolambda tasks depend on a custom task which extracted the required classes into the javaCompile output directory (build/retrolambda/$variant) so retrolambda will also transform the library classes and this worked beautifully.

// I have the java 8 dependencies as 'provided' scope, so the dex compiler will
// not complain about them. This task occurs before retrolambda and extracts
// them into the retrolambda's input directory.
task beforeRetrolambda << {
    copy {
        // Copy all the classes in debug config
        configurations.provided.asFileTree.each {
            from(zipTree(it))
        }
        into 'build/retrolambda/debug/'
        include '**/*.class'
    }

    copy {
        // Copy all the classes in release config
        configurations.provided.asFileTree.each {
            from(zipTree(it))
        }
        into 'build/retrolambda/release/'
        include '**/*.class'
    }
}

// Hook them to retrolambda, so you get transformed classes for the libraries.
afterEvaluate {
    compileRetrolambdaDebug.dependsOn beforeRetrolambda
    compileRetrolambdaRelease.dependsOn beforeRetrolambda
}

Retrolambda now assumes that all these classes are from your android application module, and includes them in dex file and the apk. This is how it worked for me.

sriharshachilakapati avatar May 23 '16 10:05 sriharshachilakapati