The covariant canonical gauge theory of gravity is generalized by including at the Lagrangian level all possible quadratic curvature invariants. In this approach, the covariant Hamiltonian principle and the canonical transformation framework are applied to derive a Palatini type gauge theory of gravity. The metric gμν, the affine connection γλμν and their respective conjugate momenta, kμνσ and qηαξβ tensors, are the independent field components describing the gravity. The metric is the basic dynamical field, and the connection is the gauge field. The torsion-free and metricity-compatible version of the spacetime Hamiltonian is built from all possible invariants of the qηαξβ tensor components up to second order. These correspond in the Lagrangian picture to Riemann tensor invariants of the same order. We show that the quadratic tensor invariant is necessary for constructing the canonical momentum field from the gauge field derivatives, and hence for transforming between Hamiltonian and Lagrangian pictures. Moreover, the theory is extended by dropping metric compatibility and enforcing conformal invariance. This approach could be used for the quantization of the quadratic curvature theories, as for example in the case of conformal gravity.