我在src / main / java / com / company / project / Config.java中有以下课程:
public class Config {
public static final boolean DEBUG = true;
...
}
Run Code Online (Sandbox Code Playgroud)
因此,在其他某个类中,我可以知道Java编译器在评估结果为false时会剥离if()语句,从而可以执行以下操作:
import static com.company.project.Config.DEBUG
if (DEBUG) {
client.sendMessage("something");
log.debug("something");
}
Run Code Online (Sandbox Code Playgroud)
在Gradle中,什么是在编译时过滤和更改Config.java中的DEBUG值而不修改原始文件的最佳方法?
到目前为止,我在想:
以上可能吗?有没有更好的办法?