Eclipse Tycho, a Maven plugin for building Eclipse plugins, raises a compile error that Eclipse IDE does not: Cannot refer to a non-final variable urlString inside an inner class defined in a different method
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:0.19.0:compile (default-compile) on project org.nodeclipse.ui: Compilation failure: Compilation failure:
[ERROR] D:\Workspaces\Nodeclipse-DEV\nodeclipse-1\org.nodeclipse.ui\src\org\nodeclipse\ui\preferences\NodePreferencePage.java:[93]
[ERROR] URL url = new URL(urlString);
[ERROR] ^^^^^^^^^
[ERROR] Cannot refer to a non-final variable urlString inside an inner class defined in a different method
[ERROR] 1 problem (1 error)
The fix is trivial, simply add a final
.
However I was wondering why the compilation with Tycho is different from Eclipse IDE? Both have Java version set to 1.6 (see in pom.xml)
Details on the project setup:
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
However I did run over JVM 8 and I had workspace default to 1.8
I doubt that you have configured Eclipse to build for Java 6. For me, the JDT allows access to non-final variables in closures if and only if I set the JDK compliance level to 1.8. So you apparently have the wrong compiler settings in Eclipse.
Obviously it is error-prone if you have to keep Eclipse and Tycho settings in sync manually. Therefore, the recommendation is to configure the compiler settings for both via the execution environment:
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
in all plug-in manifests. (The PDE doesn't support configuration inheritance, so you unfortunately have to do this in every plug-in project.).project
files checked in, make sure that all projects have project-specific compiler settings enabled, and that the option Use compliance from execution environment on the Java Build Path is selected. This setting is stored in .settings/org.eclipse.jdt.core.prefs
, so this file also needs to be checked in. You can omit this step if don't have the .project
files checked in but use m2eclipse to import your projects.tycho-compiler-plugin
source
&target
configuration, and the target-platform-configuration
executionEnvironment
configuration, if present. This makes sure that the execution environment from the bundle manifest is used to determine the compiler settings in Tycho. (See the Tycho Execution Environments configuration for details)