The 4200 is a front sump engine so thats not a problem. Suit yourself.
What I mean is the 4.2 has a front sump and the engine needs a rear sump to clear the front differential.
Add to that adapting the Jeep 5 speed to the GM engine. And the mentioned wide top end of the 4.2 makes problems finding room for for AC and power steering.If the tranny/tranfercase needs to be relocated fore or aft to accommodate the 4.2 that means driveshafts and linkages to deal with.
I've swapped a lot of engines,some difficult,but for this vehicle it's my opinion just because the 4.2 can make more power doesn't make it the right engine in my case.
But anyway,for the record,I measure the 4.0 inline at 27 inches overall length,and 17 inches tall from the oil pan rail to top of valve cover . And it's a tight fit in the Cherokee front to back and just clears the hood in the front.