|Stem cells require different types of supporting cells, or niches, to control stem cell maintenance and differentiation. However, little is known about how those niches are formed. We report that in the development of the Drosophila melanogaster ovary, the Hedgehog (Hh) gradient sets differential cell affinity for somatic gonadal precursors to specify stromal intermingled cells, which contributes to both germline stem cell maintenance and differentiation niches in the adult. We also report that Traffic Jam (an orthologue of a large Maf transcription factor in mammals) is a novel transcriptional target of Hh signaling to control cell-cell adhesion by negative regulation of E-cadherin expression. Our results demonstrate the role of Hh signaling in niche establishment by segregating somatic cell lineages for differentiation.