0

Using gradle 4.10.2

@Table
public class MyClass{
    public static final String COL_NAME = "name";
    public static final String COLTYPE_NAME = DB.DataType.VARCHAR;
    @Column(name = COL_NAME, columnDefinition = COLTYPE_NAME)
    private String name;
}

This should not be a syntax error, but when I run gradle clean publishtomavenlocal, I get

@Column(name = COL_NAME, columnDefinition = COLTYPE_NAME) error: element value must be a constant expression

                                             ^

the above is pointing at COLTYPE_NAME.

DB.DataType.VARCHAR is defined as

public final class DB{
    public static final class DataType{
        public static final VARCHAR = "varchar";
    }
}

How to fix this problem with gradle?

theAnonymous
  • 1,701
  • 2
  • 28
  • 62
  • 1
    It is not a Gradle problem, it's a Java problem, caused by the fact that `DB.DataType.VARCHAR` is not a **compile-time** constant. `COL_NAME` is a compile-time constant, since it is declared in the same compilation unit (source file), but `DB.DataType.VARCHAR` references a different compilation unit that can be compile separately, so it is not a compile-time constant to *this* compilation unit. – Andreas Apr 23 '21 at 19:37
  • This is so weird. I have been doing this for quite a while and didnt have problems before. – theAnonymous Apr 23 '21 at 19:42

0 Answers0