Starfleet is obviously a military; what it is not, is militarISTIC. There is a difference.
As for UESPA, I always assumed that it was a scientific research agency that would occasionally 'hire' Starfleet vessels to do work for it. Much like the Reliant
in ST II and how it was handling things for Project Genesis.