Generating .java file before compilation during build time

Right now I have 2 build targets: GooglePlay and Amazon. In the Java code, the code has some checks to see what it should do based on the build type. The problem is that each time you want to build for Amazon, you have to manually edit the source Java code to change the build type to Amazon. What would be the best way to generate a .java file during build time, before Java code is compiled? I guess I’m looking for something like Android, which generates R file, which you can access from code.