We construct two classes of Gray maps, called type-I Gray map and type-II Gray map, for a finite p-group G. Type-I Gray maps are constructed based on the existence of a Gray map for a maximal subgroup H of G. When G is a semidirect product of two finite p-groups H and K, both H and K admit Gray maps and the corresponding homomorphism psi: -> H Aut(K) is compatible with the Gray map of K in a sense which we will explain, we construct type-II Gray maps for G. Finally, we consider group codes over the dihedral group D-8 of order 8 given by the set of their generators, and derive a representation and an encoding procedure for such codes.