0

在我使用 Gradle(Windows 7、Java 1.7.0.15)构建的现有项目中,我已经升级了 Mybatis 库,如下所示:

// 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"

现在,当我构建时,出现以下错误:

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

我已经检查了这个类一百次,它确实覆盖了正确的方法(事实上 Eclipse 同意它没有显示错误)。

我不知道为什么在一切都应该在 Java 7 之下时使用内部 Gradle 类 jdk6。有人知道这里发生了什么 id 吗?

Gradle 不喜欢的类:

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;
    }
}

但据我所知,它没有任何问题。正确的方法被覆盖。

确定修复了构建:

在方法中添加:

public DateTime getNullableResult(ResultSet rs, int columnIndex) 抛出 SQLException;

如果我在此方法上使用覆盖注释,但没有注释 Gradle 构建成功完成,则会出现 Eclipse 错误。如果该方法被删除,Gradle 会产生一个错误,指出该类需要覆盖具有该签名的方法(或被声明为抽象)。

因此,尽管我的问题已解决,但我并不真正了解此错误的性质。

4

1 回答 1

1

Gradle 支持多种调用 Java 编译器的方式。其中之一是通过 JDK 6 Java 编译器 API,它存在于 JDK 6 及更高版本中。gradle -v会告诉你哪个 JDK 用于执行 Gradle。默认情况下,相同的 JDK 将用于编译 Java 代码。

至于编译错误,我需要更多信息来帮助(Gradle 版本、源代码、compile类路径的打印输出、可重现的示例等)。如果代码在 Eclipse 中编译而不在 Gradle 中编译,则 Gradle 和 Eclipse 的配置可能不同,例如在它们的编译类路径方面。

于 2013-03-27T12:15:59.900 回答