web-dev-qa-db-fra.com

Retrolambda: Lint se bloque lors de l'utilisation d'expressions lambda avec retrolambda

J'essaie d'utiliser retrolambda avec gradle-retrolambda plugin. En général, cela fonctionne bien, mais lorsque je compile pour publication, l'étape lint échoue à l'exception:

:playground.dagger:lintVitalReleaseFailed converting ECJ parse tree to Lombok for file D:\....\playground\dagger\MainActivity.Java
java.lang.UnsupportedOperationException: Unknown ASTNode child: LambdaExpression
    at lombok.ast.ecj.EcjTreeVisitor.visitOther(EcjTreeVisitor.Java:368)
    at lombok.ast.ecj.EcjTreeVisitor.visitEcjNode(EcjTreeVisitor.Java:364)
    at lombok.ast.ecj.EcjTreeConverter.visit(EcjTreeConverter.Java:295)
    at lombok.ast.ecj.EcjTreeConverter.toTree(EcjTreeConverter.Java:236)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.Java:282)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.Java:252)
    at lombok.ast.ecj.EcjTreeConverter.access$100(EcjTreeConverter.Java:141)
    at lombok.ast.ecj.EcjTreeConverter$2.visitMessageSend(EcjTreeConverter.Java:1042)
    at lombok.ast.ecj.EcjTreeVisitor.visitEcjNode(EcjTreeVisitor.Java:156)
    at lombok.ast.ecj.EcjTreeConverter.visit(EcjTreeConverter.Java:295)
    at lombok.ast.ecj.EcjTreeConverter.toTree(EcjTreeConverter.Java:236)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.Java:282)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.Java:252)
    at lombok.ast.ecj.EcjTreeConverter.toBlock(EcjTreeConverter.Java:397)
    at lombok.ast.ecj.EcjTreeConverter.access$1500(EcjTreeConverter.Java:141)
    at lombok.ast.ecj.EcjTreeConverter$2.visitMethodDeclaration(EcjTreeConverter.Java:1241)
    at lombok.ast.ecj.EcjTreeVisitor.visitEcjNode(EcjTreeVisitor.Java:152)
    at lombok.ast.ecj.EcjTreeConverter.visit(EcjTreeConverter.Java:295)
    at lombok.ast.ecj.EcjTreeConverter.toTree(EcjTreeConverter.Java:236)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.Java:282)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.Java:252)
    at lombok.ast.ecj.EcjTreeConverter.access$100(EcjTreeConverter.Java:141)
    at lombok.ast.ecj.EcjTreeConverter$2.createNormalTypeBody(EcjTreeConverter.Java:563)
    at lombok.ast.ecj.EcjTreeConverter$2.visitTypeDeclaration(EcjTreeConverter.Java:486)
    at lombok.ast.ecj.EcjTreeVisitor.visitEcjNode(EcjTreeVisitor.Java:48)
    at lombok.ast.ecj.EcjTreeConverter.visit(EcjTreeConverter.Java:295)
    at lombok.ast.ecj.EcjTreeConverter.toTree(EcjTreeConverter.Java:236)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.Java:282)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.Java:252)
    at lombok.ast.ecj.EcjTreeConverter.access$100(EcjTreeConverter.Java:141)
    at lombok.ast.ecj.EcjTreeConverter$2.visitCompilationUnitDeclaration(EcjTreeConverter.Java:441)
    at lombok.ast.ecj.EcjTreeVisitor.visitEcjNode(EcjTreeVisitor.Java:264)
    at lombok.ast.ecj.EcjTreeConverter.visit(EcjTreeConverter.Java:295)
    at com.Android.tools.lint.EcjParser.parseJava(EcjParser.Java:407)
    at com.Android.tools.lint.client.api.JavaVisitor.visitFile(JavaVisitor.Java:236)
    at com.Android.tools.lint.client.api.LintDriver.checkJava(LintDriver.Java:1491)
    at com.Android.tools.lint.client.api.LintDriver.runFileDetectors(LintDriver.Java:1026)
    at com.Android.tools.lint.client.api.LintDriver.checkProject(LintDriver.Java:882)
    at com.Android.tools.lint.client.api.LintDriver.analyze(LintDriver.Java:433)
    at com.Android.tools.lint.client.api.LintDriver.analyze(LintDriver.Java:374)
    at com.Android.tools.lint.LintCliClient.run(LintCliClient.Java:130)
    at com.Android.build.gradle.internal.LintGradleClient.run(LintGradleClient.Java:112)
    at com.Android.build.gradle.internal.LintGradleClient$run.call(Unknown Source)
    at com.Android.build.gradle.tasks.Lint.runLint(Lint.groovy:198)
    at com.Android.build.gradle.tasks.Lint.this$4$runLint(Lint.groovy)
    at com.Android.build.gradle.tasks.Lint$this$4$runLint$1.callCurrent(Unknown Source)
    at com.Android.build.gradle.tasks.Lint.lintSingleVariant(Lint.groovy:173)
    at com.Android.build.gradle.tasks.Lint$lintSingleVariant$0.callCurrent(Unknown Source)
    at com.Android.build.gradle.tasks.Lint.lint(Lint.groovy:75)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
    at Java.lang.reflect.Method.invoke(Method.Java:483)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.Java:63)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.Java:218)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.Java:211)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.Java:200)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.Java:579)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.Java:562)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.Java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.Java:61)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.Java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.Java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.Java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.Java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.Java:42)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.Java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.Java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.Java:43)
    at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.Java:305)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.Java:79)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.Java:63)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.Java:51)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.Java:23)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.Java:88)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.Java:29)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.Java:62)
    at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.Java:23)
    at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.Java:68)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.Java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.Java:62)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.Java:55)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.Java:149)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.Java:106)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.Java:86)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.Java:80)
    at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.Java:43)
    at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.Java:30)
    at org.gradle.tooling.internal.provider.ConfiguringBuildAction.run(ConfiguringBuildAction.Java:119)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.Java:36)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.Java:26)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.Java:47)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.Java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:119)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.Java:35)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:119)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.Java:24)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:119)
    at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.Java:33)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:119)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.Java:71)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.Java:69)
    at org.gradle.util.Swapper.swap(Swapper.Java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.Java:69)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:119)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.Java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.Java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:119)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.Java:70)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.Java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:119)
    at org.gradle.launcher.daemon.server.exec.DaemonHygieneAction.execute(DaemonHygieneAction.Java:39)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.Java:119)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.Java:46)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.Java:246)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.Java:64)
    at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1142)
    at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:617)
    at Java.lang.Thread.run(Thread.Java:745)

Y a-t-il quelque chose à faire à ce sujet? Bien sûr, un travail trivial/autour serait de désactiver lint vérifier la libération. Mais je cherche une solution, permettant de garder lint.

Voici le module de l'application build.gradle:

apply plugin: 'com.Android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.neenbedankt.Android-apt'

configurations {
    apt
}

Android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-Android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    maven{
        url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.Android.support:appcompat-v7:22.0.0'
    compile 'com.jakewharton:butterknife:6.1.0'
    compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
    compile 'de.greenrobot:eventbus:2.4.0'
    retrolambdaConfig 'net.orfjackal.retrolambda:retrolambda:1.8.1'
    apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
    provided 'org.glassfish:javax.annotation:10.0-b28'
}

Racine build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.Android.tools.build:gradle:1.1.0'
        classpath 'com.neenbedankt.gradle.plugins:Android-apt:1.4'
        classpath 'me.tatarka:gradle-retrolambda:2.5.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}
43
Denis Itskovich

Vous pouvez utiliser un version lombok spéciale avec des peluches qui ne gémit pas sur Java 8 fonctionnalités.

buildscript {
    repositories {
        jcenter()
        ...
    }

    dependencies {
        classpath 'com.Android.tools.build:gradle:<version>'
        classpath 'me.tatarka:gradle-retrolambda:<version>'
        classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2'
    }

    // Exclude the version that the Android plugin depends on.
    configurations.classpath.exclude group: 'com.Android.tools.external.lombok'
}

De cette façon, vous pouvez continuer à utiliser lint sur l'ensemble du projet, même avec les dernières versions du plug-in Android Gradle.

Remarque: Si vous recevez les mêmes erreurs, essayez de mettre la configuration ci-dessus dans le haut le plus build.gradle fichier. Cela devrait alors fonctionner.

47
WonderCsabo

Il existe un problème GitHub qui traite de ce problème: https://github.com/evant/gradle-retrolambda/issues/96

L'un des commentaires dans le numéro mentionne que lint n'a jamais réellement fonctionné avec retrolambda mais plutôt, avec la dernière version de lint, "échoue bruyamment" au lieu de simplement sauter le reste du fichier lorsque un lambda a été rencontré.

Dans cet esprit, il semble qu'il y ait deux options. Premièrement, vous pouvez simplement désactiver lint comme vous l'avez mentionné dans votre question. Bien sûr, le problème avec cela est que vous perdriez l'avantage de lint en analysant le reste de votre code. La deuxième option consiste à restaurer votre version de lint de telle sorte qu'elle ne "tombe plus en panne" mais saute simplement la vérification de la source liée à lambda; de cette façon, lint peut toujours analyser le reste du code source de votre application.

Selon le problème GitHub, restaurer votre version lint à partir de 24.0.1 (vous pouvez avoir une version différente) à 24.0.0 semble résoudre le problème. Vous pouvez trouver cette information dans le numéro (lien affiché au début de la réponse).

19
Willis