You synthesize it at the Synthesis Shop in Traverse Town, and the recipe calls for five Lucid Gems, five Power Gems, five Thunder Gems, three Mystery Goo and three Gales.
Lucid Gem — Gargoyles and Mummies in Halloween Town.
Power Gem — Battleships and Air Pirates in Neverland.
Thunder Gem — Screwdrivers and Aquatanks in Atlantica.
Mystery Goo — White Mushrooms found across random worlds, but only after you have hit them with your third spell.
Gale — Invisibles and Angel Stars.
The important catch is sequencing: the Ultima Weapon recipe only becomes available once you have synthesized every other item the Moogles offer, so early collection is not wasted effort. Whether the Gale is strictly required is still argued over, but gathering it costs little.