If you have 2 1/2 to 3 quart (2-3l) stovetop-friendly gratin dish, use that for preparing the vegetables. (You'll be baking the gratin in the same dish.) If your gratin (or similar sized dish, like a lasagna or braising pan) can't be used on the stovetop, prepare the vegetables in a large skillet.
Heat the olive oil in the dish or pan. Add the onions and carrots. Season with salt and pepper and cook until the vegetables are wilted, stirring frequently, about 10 minutes. Add the garlic, cook for another minute, then add the wine (or water or bean liquid), scraping the bottom of the pan to remove any stuck-on or browned bits of vegetables. When the wine has been absorbed, add the kale and cook until wilted. Preheat the oven to 475ºF (245ºC).
Add the tomatoes and bring to a simmer. Add the drained beans and cook everything together 5 to 10 minutes, adding up to 1/2 cup of stock if the mixture looks dry. Taste, and season with additional salt, if necessary. If you've prepared the vegetables and beans in a skillet, up to this point, transfer them to an oven-safe baking dish (as mentioned in step #1).
Sprinkle the mozzarella on top of the beans, then the Parmesan, and bake for 15 minutes until the cheese is melted and browned on top. If you wish, run the gratin under the broiler until the topping is browned to your liking. (If making garlic bread, you can cook it at the same time under the broiler.) Remove the gratin from the oven, top with parsley, and serve.