We present a formalism for determining the cross section for exclusive heavy vector meson production ($J/\ensuremath{\psi},\mathrm{\ensuremath{\Upsilon}}$) as a function of rapidity, in both high-energy proton-proton and proton-heavy ion collisions, at next-to-leading order in QCD. We compare and contrast the production in $pp$ and $p$-Pb collisions and show how data for these processes can give information on the low-$x$ gluon distribution of the proton and heavy ions at a range of different scales.