You may be using an earlier version of SDF, where <gravity> was under <physics>. From SDF 1.6 it is under <world>.