Cell wall formation. ATP + 2 D-alanine = ADP + D-alanyl-D-alanine + H(+) + phosphate Binds 2 magnesium or manganese ions per subunit. Cell wall biogenesis; peptidoglycan biosynthesis. Belongs to the D-alanine--D-alanine ligase family.