It depends ON THE GUN's DESIGN.
You generally can't move up from 9mm (in a gun built for 9mm) to a higher caliber, but you can sometimes move DOWN to 9mm from a larger caliber. It sometimes takes more than a barrel swap when moving down...
The same model gun in a larger caliber will often have a beefier frame, and barrels for the different calibers are sometimes different diameters -- so they won't necessarily fit properly if swapped. To make matters worse, the slides won't always swap, either. (Witness now uses the same frame on all of their guns, so all that's needed to change calibers is a new top end.) As noted above, some other spring changes may be necessary -- but not always.
Companies build "conversion" barrels that allow the larger caliber guns to work with a smaller caliber round. (I have a Glock 23 with the stock .40 barrel, a .357 SIG barrel, and a 9mm conversion barrel. All three can use the same magazine, but that isn't always the case with such conversions.)
Conversion barrels are generally built so that headspace is correct and the extractors work as they should.
Unless you've got one of the guns designed like the Witness line, you're stuck with 9mm, or a .22 kit.