Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling GWT 2.6.1 at Java 7 source level

Tags:

java

ant

gwt

I've recently updated my GWT project to 2.6.1, and started to make use of Java 7 syntax since 2.6 now supports Java 7.

However, when I attempt to compile, I'm receiving compiler errors such as

[ERROR] Line 42: '<>' operator is not allowed for source level below 1.7

Full output

Compiling module com.Project
   Validating units:
      Ignored 85 units with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
   Computing all possible rebind results for 'com.google.gwt.useragent.client.UserAgentAsserter'
      Rebinding com.google.gwt.useragent.client.UserAgentAsserter
         Checking rule <generate-with class='com.google.gwt.editor.rebind.SimpleBeanEditorDriverGenerator'/>
            [WARN] Detected warnings related to 'com.google.gwt.editor.client.SimpleBeanEditorDriver'.   Are validation-api-<version>.jar and validation-api-<version>-sources.jar on the classpath?
            Specify -logLevel DEBUG to see all errors.
            [WARN] Unknown type 'com.google.gwt.editor.client.SimpleBeanEditorDriver' specified in deferred binding rule
   [ERROR] Errors in 'file:/C:/workspace/Project/src/com/project/ProjectFile.java'
      [ERROR] Line 42: '<>' operator is not allowed for source level below 1.7
   [ERROR] Errors in 'file:/C:/workspace/Project/src/com/project/AnotherProjectFile.java'
      [ERROR] Line 188: Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum variables are permitted
C:\workspace\Project\build.xml:51: Java returned: 1
    at org.apache.tools.ant.taskdefs.Java.execute(Java.java:111)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.Main.runBuild(Main.java:809)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.Main.start(Main.java:180)
    at org.apache.tools.ant.Main.main(Main.java:268)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:30)
C:\workspace\Project\build.xml:51: Java returned: 1
    at org.apache.tools.ant.taskdefs.Java.execute(Java.java:111)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.Main.runBuild(Main.java:809)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.Main.start(Main.java:180)
    at org.apache.tools.ant.Main.main(Main.java:268)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:30)
C:\workspace\Project\build.xml:51: Java returned: 1
    at org.apache.tools.ant.taskdefs.Java.execute(Java.java:111)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.Main.runBuild(Main.java:809)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.Main.start(Main.java:180)
    at org.apache.tools.ant.Main.main(Main.java:268)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:30)

How do I specify the GWT compiler to target 1.7? I was under the impression that it would do that by default, but I guess not. I've attempted cleaning the project, including deleting the gwt-unitCache directory but to no avail.

Here is my Ant compile target.

<target name="compile" depends="prepare">
    <javac includeantruntime="false"
           debug="on"
           debuglevel="lines,vars,source"
           srcdir="${src.dir}"
           destdir="${build.dir}"
           source="7"
           target="7">
        <classpath refid="project.classpath"/>
    </javac>
</target>

<target name="gwt-compile" depends="compile">
    <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
        <classpath>
            <!-- src dir is added to ensure the module.xml file(s) are on the classpath -->
            <pathelement location="${src.dir}"/>
            <pathelement location="${build.dir}"/>
            <path refid="project.classpath"/>
        </classpath>
        <jvmarg value="-Xmx256M"/>
        <arg value="-sourceLevel"/><arg value="7"/>
        <arg value="${gwt.module.name}"/>
    </java>
</target>
like image 1000
Cooper Avatar asked May 30 '14 15:05

Cooper


People also ask

Does GWT support Java 11?

The release was tested and found to work cross platform when run with Java 8, 11, and 14.

Does GWT support Java 8?

As long as GWT uses JDT for its Java parsing/munging/compiling, Java 8 can only be supported when JDT will support it (at an acceptable level, which is not yet the case AFAICT).


1 Answers

The GWT Compiler (and SuperDevMode's CodeServer) has a -sourceLevel argument that you can use to specify the language level, similar to the -source argument of javac.

The default value of -sourceLevel depends on your current JVM, so it should default to Java 7 if you use a JDK 1.7.

It's a good practice to be explicit and pass -sourceLevel 7 (or 1.7) to GWT, anda -source 7 (or 1.7) to javac (use source="7" in your <javac> Ant task)

like image 151
Thomas Broyer Avatar answered Oct 16 '22 08:10

Thomas Broyer