I have different levels of defence.
First, to deal with the non trap avoid invaders, a narrow path with harmless traps above a 2 z-levels pit filled with 1z level of water. It's a dodge-me trap setup, and the killing is done by the water: I am in a cold biome, so when the water is not frozen, the invaders fall in it but don't drown. They die when the water freezes, encased in ice. If they invade when the water is already frozen, the fall onto the ice, and are contained there, until the ice melts (then they get in the water), and eventually it will freeze again and encase them in ice.
For the trap avoid buggers (e.g. chaos dwarves, I use the civilization forge mod), I have bridges linked to levers. Lots of small bridges, because I found out at my expense that large mounts prevent bridges from retracting: once, a leader mounted on a land strider stopped the large bridges from retracting, and since his squad was right next to him on the same large bridge, his followers made it safely to my central shaft and much Fun ensued. Chaos dwarves have very good gear (steel or better), and I ... didn't.
On warm/hot/scorching biomes, I usually set up a flush defence, which pushes enemies into a pit thanks to a water fall system. Aquifers are a big plus for this.
Military is rarely part of my defense plans. But I do have many builders and mechanics.
For last ditch defence, I always set up a U bend type stair case with hatches, so I can lock myself away. Hatches cannot be destroyed from the z-level below, so this defense is completely impenetrable. The U bend is floodable on the invader side, and underground, so will drown anyone there regardless of the biome (no freezing/evaporating)