Josephson junction dynamics in the presence of inhomogeneities