Java/ groovy build order error?

Given a Java interface (Formatter.java)

public interface Formatter {
   Object parse(String text) throws ParseException;
   }

in a .java file and an abstract Groovy class (AbstractFormatter.groovy)

abstract class AbstractFormatter implements Formatter, Serializable {
    abstract protected Object stringToValue(String text) throws ParseException;
 abstract protected String valueToString(Object value) throws ParseException;
   Object parse(String text) {
  return stringToValue(text)
 }
}

running a build under Linux and Windows from the command line results in an error:

AbstractFormatter.groovy: 59: The return type of java.lang.Object parse(java.lang.String) in com.metaficient.core.objectmodel.formatters.AbstractFormatter is incompatible with [Ljava.util.Formatter$FormatString; parse(java.lang.String) in java.util.Formatter
. At [59:2]
@ line 59, column 2.
    Object parse(String text) {
    ^
  1 error

I did some experiments using Groovy 1.8.6 to compile the files manually, and it seems that this happens when the .java interface file is not compiled before the .groovy file. This happens on Linux and Windows from the command line, but NOT on Mac OS X, or when running under the gradle -gui option.

The build file is:

import java.text.SimpleDateFormat
  // apply plugin: 'eclipse'
apply plugin: 'groovy'
  version = hasProperty('versionID') ? versionID : new SimpleDateFormat('yyyyMMdd').format(new Date())
  repositories {
 flatDir {
  dir 'src/main/lib'
 }
 flatDir {
  dir 'src/test/lib'
 }
 mavenCentral()
}
  dependencies {
 groovy group: 'org.codehaus.groovy', name: 'groovy-all', version: '1.8.6'
 compile ':castor:1.2',
   ':commons-beanutils:1.8.3',
  ':commons-collections:3.2.1',
  ':commons-digester:2.1',
  ':commons-logging:1.1.1',
  ':commons-io:2.4',
  ':datecalc-common:1.2.0',
  ':datecalc-jdk:1.2.0',
  ':datecalc-joda:1.2.0',
  ':itext:2.1.7',
  ':jasperreports:4.1.1',
  ':joda-time:2.0',
  ':jollyday:0.4.4',
  ':log4j:1.2.16',
  ':opencsv:2.3',
  ':prevayler:2.3',
  ':xpp3_min:1.1.4c',
  ':xstream:1.3.1'
     testCompile group: 'junit', name: 'junit', version: '4.8.2',
  ':fest-assert:1.4',
  ':fest-reflect:1.2',
  ':fest-util:1.1.6',
  ':gmock:0.8.1'
}

If I change the .java file to .groovy, it now works.

This is gradle 1.2, Sun java 1.6.0_35 and groovy 1.8.6 on Suse Linux and Windows 7 (under both Windows cmd and a Cygwin shell)

Groovy imports ‘java.util.*’ by default. Looks like the Groovy compiler interprets ‘implements Formatter’ to mean ‘implements java.util.Formatter’ and then goes astray. You should be able to solve the problem with an explicit import of your ‘Formatter’ interface (even if it’s in the same package). I don’t think the problem is related to Gradle.