XJ Cherokee and ZJ Grand Cherokee 4.0L engine blocks interchange.
2000+ TJ Wrangler and WJ Grand Cherokee 4.0L engine blocks interchange.
XJ/ZJ blocks and 2000+ TJ/WJ blocks do not interchange without significant modifications. (1991 to 1995 YJ and 1997-1999 4.0L TJ Wrangler blocks will interchange in XJ/ZJ and visa-versa).
TJ/WJ 4.0L Engine blocks underwent clean sheet design changes effective in the 1999 WJ Grand and 2000 TJ Wrangler. These blocks are not interchangeable with XJ/ZJ engine blocks. The reason is motor mount bolt holes and belt driven accessory mounting bolt holes are in different locations, or not present at all, TJ/WJ vs. XJ/ZJ.
XJ: "Regular" (not Grand) Cherokees 84-01
ZJ: Grand Cherokee 93-98 (Gen1)
WJ: Grand Cherokee 99-04 (Gen2)
YJ: Wrangler 87-95 (Gen1)
TJ: Wrangler 97-06 (Gen2)