Defend the Castle

Defend the Castle is a Minutemen main quest in Fallout 4.

Quick walkthrough
Objective: Go to the Castle and defend it after you build the defenses.

The Institute synths are planning to attack the Castle. Keep in mind that you need eight Settlements for this quest to begin. You can listen to Radio Freedom for information related to the attack. Defend the Castle and speak with Ronnie and Preston afterwards.

After "With our powers combined," the Brotherhood of Steel will attack The Castle. Radio Freedom will call upon the Minutemen to defend and give information related to the attack.

Sometimes, the Castle can also be attacked by Raiders. Radio Freedom will call upon the Minutemen and give info related to the attack.

Detailed walkthrough
This quests consists of "waves" where a limited number of attackers will spawn and attempt to take over The Castle.

Brotherhood of Steel
Waves consists of 1 vertibird and its occupants which put together, consists of a total of 10 Vertibirds and about 30 BoS soldiers. The most efficient way to complete this quest is to use Missile Turrets. The turrets will make short work of the Vertibirds and its occupants. Most of the men inside the ship will not be lootable with the exception of ragdolls falling out. So if you are looking for loot, this method is not recommended.

Institute
Waves of Synths and Coursers will spawn at various locations. Building walls beforehand to block the holes in the wall will prevent most enemies from entering and prevent the player being surrounded.

Raiders or Gunners
Waves of Raiders and Attack Dogs or Gunners will attack from either the front side or the back. Again, building walls beforehand to block the holes will make things easier.

Super Mutants
Waves of Super Mutants will spawn with Behemoths. Again, shoring up the walls is recommended.

Bugs

 * Many quests involving the railroad, such as the weathervane, and Randolph quests will automatically fail if not completed before hand.
 * It is a possibility that Ronnie Shaw's proper dialogue will not appear to end the quest; the only options that will appear are trading and merchant dialogue, leaving the quest unbeatable. There is no known fix for this bug.
 * Sometimes, enemy waves will not move upon spawning or will move in the wrong direction in an attempt to fight other enemies in the area. If the quest appears to be stuck, try looking for the enemy wave nearby, and then drawing them back to the castle. Synths can also teleport into the player-made structures, so make sure they are not hidden in or amongst any place that may appear inaccessible.
 * It is possible to glitch the quest during the Synth attack in such a way that all guns, energy weapons, and explosives including Minutemen artillery will cease dealing damage. From that point on, NPCs and the player may fire or throw grenades at each other to no effect, and only bashing or other melee attacks will deal damage.