It was likely passed down orally for generations before being written down. The earliest known written version is from the collection "Children's and Household Tales" by the Brothers Grimm, published in 1812. However, they weren't the originators of the story, but rather collectors and editors of folk tales.