Heat oven to 400° F. Place the bread in a buttered ovenproof skillet, a 9-inch square baking dish, or a casserole. Scatter the onion and ham over the bread. Pour the wine over the onion and ham and sprinkle with the pepper and Gruyère.
Bake until the cheese has melted and begun to brown at the edges, about 20 minutes. Spoon onto individual plates.