In this work we assess the applicability of the adjoint optimization technique for determining optimal surface topographies of two surfaces in relative motion in presence of a thin lubricant films that can cavitate. Among the existing numerical tools for topology optimization in engineering problems, the adjoint method represents a promising and versatile technique, which can also be applied to the field of full film tribology. In particular, the design of surfaces with complex textures can thoroughly benefit from this method, as it allows dealing with a large number of degrees of freedom at low computational cost. We show that this optimization method can be successfully applied to cavitating lubricant flows such as in pin-on-disc tribometers, giving the possibility to extend the results also to other typical applications such as journal and slider bearings. It is shown that the adjoint method can optimize the whole gap height distribution point by point in a more efficient way than traditional optimization approaches and parametric studies. In particular, thanks to the sensitivity analysis the adjoint method is able to find the placement and depth profile of each texture element.