The problem in WAR (or rather one of the problems) was that there was no incentive to defend. While one team was attacking keep A, it was more profitable (exp/coin/etc. wise) for another team to attack keep B. Later on when the first team comes to take keep B, the second would move on to keep A. Hence the term - “swapping keeps”.
In GW2, they seem to have fixed this issue by providing multiple incentives to defend stuff. When you escort a caravan, not only you ensure that supply gets to your keep and helps to defend it, you also get an escort dynamic event completion, which gives you exp/coin/etc. When the enemy attacks something (keep/tower/etc.), and your team repels that attack, you get a defence dynamic event completion. And so on.
When a guild claims a captured object, all allies around that object will receive some buffs depending on how that guild spent their influence. Obviously, if the object is lost, those buffs are lost as well.
Some keeps have waypoints inside them and controlling those waypoints allows your team to move around the map faster.
You can upgrade and fortify keeps, towers, etc., which makes them easier to defend. It takes some resources to fortify (supply, coin) and this investment will need to be defended.
All objects captured by your team contribute to the amount of WvW points your server receives periodically. These points enable more and more points for your entire server. Obviously, if you just swap keeps, you get much less of those points as if you’d get by defending what’s yours and attacking what’s theirs.
Additionally, there are 3 servers in the conflict. Thus if you don’t defend, there is a risk that the 2 enemy servers will take more from you than what you will be able to capture. Again, this will help to prevent swapping.
Additionally, the aforementioned supply is not only a defensive resource, it’s used for offence as well. If your team doesn’t control keeps, towers, supply camps, caravans you won’t have resources to take stuff from the enemy. And you need to control all those objects continuously because the resource (supply) is not instantaneous, it takes time to accumulate.
Additionally, WvW currency (Badge of Honor or something like that) is dropped by the enemies you kill. If you do a WAR-style uncontested swapping, you won’t get any of that.
It seems ANet has a bunch of WvW mechanics working together to ensure that offence and defence are both required and are both profitable to the server as a whole as well as to the players as individuals.