In an existing project I build with Gradle (Windows 7, Java 1.7.0.15) I have upgraded the Mybatis libraries as follows:
// MyBatis
compile "org.mybatis:mybatis:3.2.1"
compile "org.mybatis:mybatis-spring:1.2.0"
//compile "org.mybatis:mybatis:3.0.6"
//compile "org.mybatis:mybatis-spring:1.0.2"
Now when I build I get the following error:
11:38:37.308 [INFO] [org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler]
Compiling with JDK 6 Java compiler API.
11:38:39.147 [ERROR] [system.err] ...java:14: error: DateTimeHandler is not abstract and does not override abstract method getNullableResult(ResultSet,int) in BaseTypeHandler
11:38:39.153 [ERROR] [system.err] public class DateTimeHandler extends BaseTypeHandler<DateTime> {
11:38:39.274 [ERROR] [system.err] Note: Some input files use or override a deprecated API.
11:38:39.279 [ERROR] [system.err] Note: Recompile with -Xlint:deprecation for details.
11:38:39.284 [ERROR] [system.err] 1 error
I have checked the class a hundred times and it DOES overide the correct method (in fact Eclipse agrees in that it shows no errors).
I don't know why an internal Gradle class jdk6 is being used when everything should be under Java 7. Does anybody know what id going on here?
The class which Gradle doesn't like:
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedTypes;
import org.joda.time.DateTime;
@MappedTypes(value = DateTime.class)
public class DateTimeHandler extends BaseTypeHandler<DateTime> {
public DateTimeHandler() {
}
@Override
public void setNonNullParameter(PreparedStatement ps, int i, DateTime parameter, JdbcType jdbcType) throws SQLException {
ps.setTimestamp(i, new java.sql.Timestamp((parameter.toDate()).getTime()));
}
@Override
public DateTime getNullableResult(ResultSet rs, String columnName) throws SQLException {
java.sql.Timestamp sqlTimestamp = rs.getTimestamp(columnName);
if (sqlTimestamp != null) {
return new DateTime(sqlTimestamp.getTime());
}
return null;
}
@Override
public DateTime getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
java.sql.Timestamp sqlTimestamp = cs.getTimestamp(columnIndex);
if (sqlTimestamp != null) {
return new DateTime(sqlTimestamp.getTime());
}
return null;
}
}
But there is nothing wrong with it as far as I can see. The correct methods are overiddden.
OK fixed the build:
Added in the method:
public DateTime getNullableResult(ResultSet rs, int columnIndex) throws SQLException;
Eclipse errors if I use the override annotation on this method, but without the annotation the Gradle build completes successfully. If the method is removed Gradle produces an error saying that the class needs to override a method with that signature (or be declared abstract).
So although my problem is fixed I don't really understand the nature of this error.
Gradle supports multiple ways of invoking the Java compiler. One of them is via the JDK 6 Java compiler API, which exists in JDK 6 and higher. gradle -v
will tell you which JDK is used for executing Gradle. By default, the same JDK will be used for compiling Java code.
As to the compile error, I would need more information to help (Gradle version, source code, printout of compile
class path, reproducible example, etc.). If the code compiles in Eclipse but not in Gradle, chances are that Gradle and Eclipse are configured differently, for example in terms of their compile class path.