2

I'm trying to use Guava 12.0's FluentIterable with GWT 2.0.3, like so:

import com.google.common.collect.FluentIterable;

class FooPresenter {
   // snip

   private List<NullSafeCheckBox> asCheckboxes() {
      return FluentIterable.from(getDisplay().getMetricInputs())
         .transform(new Function<HasValueChangeHandlers<Boolean>, NullSafeCheckBox>() {
            @Override
            public NullSafeCheckBox apply(@Nullable HasValueChangeHandlers<Boolean> checkbox) {
               return (NullSafeCheckBox) checkbox;
            }
         })
         .toImmutableList();
   }
}

However, when I run GWT in dev mode, I get the following error when trying to load the first module:

DEBUG: Validating newly compiled units
  ERROR: Errors in 'jar:file:/home/josh/.m2/repository/com/google/guava/guava-gwt/12.0/guava-gwt-12.0.jar!/com/google/common/math/super/com/google/common/math/LongMath.java'
    ERROR: Line 23: The import java.math cannot be resolved

My pom.xml looks like this:

  <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>12.0</version>
  </dependency>
  <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava-gwt</artifactId>
      <version>12.0</version>
  </dependency>

And my Application.gwt.xml sucks in Guava like this:

<!-- Guava -->
<inherits name="com.google.common.collect.Collect"/>

Update

Following the advice in Arcadian's answer, I added gwt-math to my pom.xml and my Application.gwt.xml:

  <!-- Guava -->
  <inherits name="com.google.common.collect.Collect"/>
  <inherits name="com.googlecode.gwt.math.Math" />

Now I get this error when running hosted mode:

DEBUG: Validating newly compiled units
  WARN: Warnings in 'jar:file:/home/josh/.m2/repository/videoplaza-third-party/gwt-incubator/20100204-r1747/gwt-incubator-20100204-r1747.jar!/com/google/gwt/widgetideas/client/impl/GlassPanelImpl.java'
    WARN: Line 30: Referencing deprecated class 'com.google.gwt.user.client.impl.DocumentRootImpl'
    WARN: Line 38: Referencing deprecated class 'com.google.gwt.user.client.impl.DocumentRootImpl'
  ERROR: Errors in 'jar:file:/home/josh/.m2/repository/com/google/guava/guava-gwt/12.0/guava-gwt-12.0.jar!/com/google/common/primitives/UnsignedLong.java'
    ERROR: Line 77: The method bitLength() is undefined for the type BigInteger
    ERROR: Line 79: The method longValue() is undefined for the type BigInteger
    ERROR: Line 200: The method valueOf(long) is undefined for the type BigInteger
    ERROR: Line 202: The method setBit(int) is undefined for the type BigInteger
Community
  • 1
  • 1
Josh Glover
  • 25,142
  • 27
  • 92
  • 129

2 Answers2

2

You can try to add gwt-java-math project as dependency. As said on their wiki,

This library is in the process of getting merged into GWT itself! Currently it is on GWT trunk.

It may be available in the upcoming v2.5.

Arcadien
  • 2,258
  • 16
  • 26
  • Thanks! That got me along to the next error, at least. :) See update to my original question. – Josh Glover Jun 29 '12 at 09:08
  • 1
    I think you must remove the non-gwt guava dependency. It may restrict the number of available guava classes, but ensure they are GWT-ized. Say, choose between guava-java and guava-gwt, using both may confuse classloader – Arcadien Jun 29 '12 at 09:20
  • [This answer](http://stackoverflow.com/a/6201161/58994) indicates that you need both Guava deps in your POM, and in fact it didn't work for me when I omitted the non-GWT Guava. – Josh Glover Jul 09 '12 at 13:58
0

FYI, it looks to me like java.math should be available in current versions of GWT, though probably not in 2.0.3. See, e.g., the JRE emulation reference for GWT 2.2, probably the first version where it was available.

I don't know what to expect in combination with gwt-java-math; possibly Guava itself would need to declare a dependency on its module for it to work?

We do need to do a much better of of determining and advertising which version of GWT is required for Guava, including running our GWT tests against Guava (and not just our internal version of it) to verify that.

Chris Povirk
  • 3,738
  • 3
  • 29
  • 47