Install a longer length of copper pipe, then slip the bath spout onto the pipe all the way, then measure the distance between the wall and the spout to know how much pipe to cut off. Cut off 1/4" additional to ensure expansion of the pipe will not push the spout away from the wall, thereby allowing the spout to remain firmly tight to the wall.
I typically will install silicone caulking around most of the spout and wall, to prevent water from showering, from entering and leaking into the wall cavity through the gap surrounding the protruding supply pipe. To permit water to drain if necessary, do not install caulking at the extreme bottom (6 o'clock position) of the spout.
Before installing the spout, always de-bur the end of the pipe, then place a thin coating of silicone plumbers lube on the pipe end to provide lubrication to prevent damage to the 'O-ring' seal located within the spout.