I have the following class in src/main/java/com/company/project/Config.java:
public class Config {
public static final boolean DEBUG = true;
...
}
so that in some other class I can do the following, knowing that the java compiler will strip the if() statement if it evaluates to false:
import static com.company.project.Config.DEBUG
if (DEBUG) {
client.sendMessage("something");
log.debug("something");
}
In Gradle, what is the best way to filter and change DEBUG value in Config.java at compile time without modifying the original file?
So far I'm thinking:
- Create a task updateDebug(type:Copy) that filters DEBUG and copies Config.java to a temporary location
- Exclude from sourceSets the original Config.java file and include the temporary one
- Make compileJava.dependsOn updateDebug
Is the above possible? Is there a better way?