If I was my choice, I would do it. You will need three different measurements for any shock. A extended length, a compressed length and a neutral length. Typically stock shocks are shorter then what you'd need. If you take the track bar off and disconnect the swaybar the shocks or the brake line will be you're limiting strap. This is a good way to damage either.
One reason for going to a longer/larger size shock is to keep it cool. Smaller shocks will heat up faster. A larger shock body should dissipate heat better as there is more surface area as well as fluid. The stock shocks were were also not chosen for their optimum travel since they really where not thinking about articulation, especially with a YJ.
The normal set for a 2.5L was 4/5 packs. There was also 5/5 as well as 5/6. Also, keep in mind that the YJ was 1" lower then the CJ. The main reason for the YJ being the way it was was because of the roll-over claims from the 60 Minute piece back in the 80's. AMC designed a Jeep that was less prone to rolling over and what they did was to lower the CG and lock up the suspension.
Some other considerations; the suspension is basically a lever. As you move away from the fulcrum you there will be more travel. Conversely, as you move closer to the fulcrum you will have less travel. The CJ-7's axles are not only narrower but the frame is as well. This is also why, if you triangulate a shock, you will use less travel. If you triangulate a shock 45* you will only use about 50% of the shock's travel. Although front shocks are usually mounted vertically while the rears are usually at an angle of some sort.
So, do the swap, measure and buy the appropriate shock.