[GRADLE-1329] sourceCompatibility = 1.6 broken for eclipse plugin / gradle 0.9.1 Created: 20/Jan/11  Updated: 04/Jan/13  Resolved: 25/Jan/11

Status: Resolved
Project: Gradle
Affects Version/s: 0.9.1
Fix Version/s: 1.0-milestone-1

Type: Bug
Reporter: Daniel Joyce Assignee: Peter Niederwieser
Resolution: Won't Fix Votes: 1

Issue Links:
Supercedes
Superceded by GRADLE-1350 More user-friendly behavior for the c... Resolved

 Description   

my build.gradle contains a sourceCompatibility entry

sourceCompatibility = 1.6

"gradle eclipse" using this line works under 0.9, but results in a stack trace under 0.9.1. It looks like a failed cast.

A plain "gradle" build works under both 0.9 and 0.9.1

STACK TRACE:

12:30:41.835 [DEBUG] [org.gradle.api.internal.tasks.SkipTaskExecuter] Starting to execute task ':eclipseJdt'
12:30:41.835 [DEBUG] [org.gradle.api.internal.project.taskfactory.ExecutionShortCircuitTaskExecuter] Determining if task ':eclipseJdt' is up-to-date
12:30:41.836 [DEBUG] [org.gradle.api.internal.project.taskfactory.ExecutionShortCircuitTaskExecuter] task ':eclipseJdt' is not up-to-date
12:30:41.837 [DEBUG] [org.gradle.api.internal.tasks.DefaultTaskExecuter] Executing actions for task ':eclipseJdt'.
12:30:41.842 [DEBUG] [org.gradle.api.internal.tasks.SkipTaskExecuter] Finished executing task ':eclipseJdt'
12:30:41.852 [ERROR] [org.gradle.BuildExceptionReporter]
12:30:41.855 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
12:30:41.856 [ERROR] [org.gradle.BuildExceptionReporter]
12:30:41.856 [ERROR] [org.gradle.BuildExceptionReporter] * Where:
12:30:41.857 [ERROR] [org.gradle.BuildExceptionReporter] Build file '/home/DIMSYS/daniel/svn/utilities/rfid_kiosk/build.gradle'
12:30:41.857 [ERROR] [org.gradle.BuildExceptionReporter]
12:30:41.857 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
12:30:41.858 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':eclipseJdt'.
12:30:41.859 [ERROR] [org.gradle.BuildExceptionReporter] Cause: java.math.BigDecimal cannot be cast to org.gradle.api.JavaVersion
12:30:41.860 [ERROR] [org.gradle.BuildExceptionReporter]
12:30:41.860 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is:
12:30:41.861 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.api.tasks.LocationAwareTaskExecutionException: Build file '/home/DIMSYS/daniel/svn/utilities/rfid_kiosk/build.gradle'
12:30:41.862 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':eclipseJdt'.
12:30:41.863 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.DefaultTaskExecuter.executeActions(DefaultTaskExecuter.java:66)
12:30:41.863 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.DefaultTaskExecuter.execute(DefaultTaskExecuter.java:43)
12:30:41.864 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:32)
12:30:41.864 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.ExecutionShortCircuitTaskExecuter.execute(ExecutionShortCircuitTaskExecuter.java:50)
12:30:41.865 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.SkipTaskExecuter.doExecute(SkipTaskExecuter.java:57)
12:30:41.865 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.SkipTaskExecuter.execute(SkipTaskExecuter.java:35)
12:30:41.866 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:32)
12:30:41.866 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.AbstractTask.execute(AbstractTask.java:231)
12:30:41.867 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.DefaultTaskGraphExecuter.executeTask(DefaultTaskGraphExecuter.java:167)
12:30:41.867 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.DefaultTaskGraphExecuter.doExecute(DefaultTaskGraphExecuter.java:160)
12:30:41.868 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:78)
12:30:41.868 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.TaskNameResolvingBuildExecuter.execute(TaskNameResolvingBuildExecuter.java:113)
12:30:41.868 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.DelegatingBuildExecuter.execute(DelegatingBuildExecuter.java:54)
12:30:41.869 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:153)
12:30:41.869 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:107)
12:30:41.869 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:75)
12:30:41.870 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.RunBuildAction.execute(RunBuildAction.java:41)
12:30:41.870 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.RunBuildAction.execute(RunBuildAction.java:27)
12:30:41.870 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.CommandLineActionFactory$WithLoggingAction.execute(CommandLineActionFactory.java:209)
12:30:41.871 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.CommandLineActionFactory$WithLoggingAction.execute(CommandLineActionFactory.java:193)
12:30:41.871 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.Main.execute(Main.java:55)
12:30:41.871 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.Main.main(Main.java:40)
12:30:41.871 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.ProcessBootstrap.runNoExit(ProcessBootstrap.java:46)
12:30:41.872 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.ProcessBootstrap.run(ProcessBootstrap.java:28)
12:30:41.872 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.GradleMain.main(GradleMain.java:24)
12:30:41.872 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.lang.ClassCastException: java.math.BigDecimal cannot be cast to org.gradle.api.JavaVersion
12:30:41.873 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.plugins.eclipse.EclipseJdt_Decorated.getSourceCompatibility(Unknown Source)
12:30:41.873 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.plugins.eclipse.EclipseJdt.this$dist$invoke$6(EclipseJdt.groovy)
12:30:41.873 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.plugins.eclipse.EclipseJdt$1.methodMissing(EclipseJdt.groovy)
12:30:41.874 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.plugins.eclipse.EclipseJdt$1.configure(EclipseJdt.groovy:44)
12:30:41.874 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.plugins.eclipse.EclipseJdt$1.configure(EclipseJdt.groovy)
12:30:41.874 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.tasks.GeneratorTask.generate(GeneratorTask.java:68)
12:30:41.875 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:158)
12:30:41.875 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:93)
12:30:41.875 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.plugins.eclipse.EclipseJdt_Decorated.invokeMethod(Unknown Source)
12:30:41.875 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23)
12:30:41.876 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$2.execute(AnnotationProcessingTaskFactory.java:131)
12:30:41.876 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$2.execute(AnnotationProcessingTaskFactory.java:130)
12:30:41.876 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.DefaultTaskExecuter.executeActions(DefaultTaskExecuter.java:58)
12:30:41.877 [ERROR] [org.gradle.BuildExceptionReporter] ... 24 more



 Comments   
Comment by Daniel Joyce [ 20/Jan/11 ]

WORKAROUND

Using the JavaVersion enum directly works

sourceCompatibility = JavaVersion.VERSION_1_6

Using the numeric version does not work in gradle 0.9.1

sourceCompatibility = 1.6

Comment by Peter Niederwieser [ 20/Jan/11 ]

I cannot reproduce this problem. Can you provide a reproducible example?

Comment by Daniel Joyce [ 21/Jan/11 ]

Gradle Version info:
------------------------------------------------------------
Gradle 0.9.1
------------------------------------------------------------

Gradle build time: Sunday, 2 January 2011 11:40:57 AM EST
Groovy: 1.7.6
Ant: Apache Ant version 1.8.1 compiled on April 30 2010
Ivy: 2.2.0
JVM: 1.6.0_18 (Sun Microsystems Inc. 14.0-b16)
OS: Linux 2.6.32.21-166.fc12.x86_64 amd64

Just discovered order of entries in build.gradle matters for gradle 0.9.1.

This is not stated anywhere in gradle docs, and appears to be a change in behaviour from 0.9.0

FAILS:
sourceCompatibility = 1.6
apply plugin: 'java'
apply plugin: 'eclipse'

WORKS:
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.6

WORKS:
sourceCompatibility = JavaVersion.VERSION_1_6
apply plugin: 'java'
apply plugin: 'eclipse'

Comment by Peter Niederwieser [ 21/Jan/11 ]

Thanks. I can reproduce it now.

Just discovered order of entries in build.gradle matters for gradle 0.9.1.

Order has always mattered to some degree, especially for plugins. Before a plugin has been applied, everything that it adds (tasks, configurations, etc.) won't be visible. That's why it's good practice to apply plugins at the very top of the script.

Anyway, I don't know why order matters in this particular case, and if it is a bug. Will have to investigate.

Comment by Peter Niederwieser [ 25/Jan/11 ]

The behavior isn't specific to 0.9.1 and is currently expected. We'll try to come up with a more user-friendly behavior in the future (I'll create a new issue for this). Meanwhile, make sure that plugins are always applied at the top of the script.

Generated at Wed Jun 30 11:52:47 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.