Exact computation of the gravitational field and gravitational gradient tensor for a general mass body is a core routine to model the density structure of the Earth. In this study, we report on the existence of closed-form solutions of the gravitational potential, gravitational field and gravitational gradient tensor for a general polyhedral mass body with a polynomial density function of arbitrary non-negative integer orders that can simultaneously vary in both horizontal and vertical directions. Our closed-form solutions of the gravitational potential and the gravitational field are singularity-free, which implies that the observation sites can have arbitrary geometric relationships with polyhedral mass source bodies. However, weak logarithmic singularities exist on the edges of polyhedra for the gravitational gradient tensor. A simple prismatic mass body with polynomial density contrast varying in the vertical direction and a complicated dodecahedral mass body with quartic-order density contrasts were tested to verify the accuracy of the newly derived closed-form solutions. For the gravitational potential, gravitational fields and gradient tensors, our closed-form solutions are in excellent agreement with previously published analytical solutions and Gaussian numerical quadrature solutions.