So, you're wondering why gravity doesn't violate the 2nd law of thermodynamics, even though the entropy of a gas cloud decreases as it shrinks under its own gravitational pull? The answer is simple, but I'll just give you a hint. We've already seen that as it shrinks, it loses energy. The energy has to go somewhere. Where does it go? If you figure that out, you'll see that the total entropy is not actually decreasing - it's just leaving the gas cloud and going somehere else!