Actually it occurs to me that there may be an ever more effective defense: make yourself a needle in a haystack.
Goblins are good miners, right? And most D&D worlds have an abundance of natural underground spaces.
First order of business is to make sure you have a good DOZEN escape tunnels which lead to exits at least 10 miles away from the main lair. No way any human force can besiege an area that large. So what if they invade one tunnel? You can easily escape out the back door, and since their army is busy, this is actually a great time to do a bit of raiding. Surface armies are limited to surface topology -- two dimensions -- and are easily blocked or surrounded. Goblins have three dimensions to work with, and should prove a slippery foe. (These escape tunnels double as launching points for raids. If you raid from the north when the lair is actually miles to the south, you've achieved a nice misdirection.) Also, make every attempt to open tunnels to other cave complexes and the rest of the underdark. It's that much more area the invaders have to search trying to find you.
(A good trick is to build tunnels to connect directly to thieves guilds in nearby towns and cities. The theives will benefit from escape tunnels and smuggling operations, and you can benefit from "inside information" and increased trade. Always better to know when an invasion is planned in advance.)
Next, mine the area around the lair like crazy. There should be MILES of tunnels in and around the lair, with complex branches and multiple levels. It would take thousands of men crawling on their hands and knees to cover and inspect all the tunnels, and since it's three dimensional it's nearly impossible to map. If they cover the whole area, they'll be spread thin and easy pickings for goblin squads. If they stay bunched up they can only cover a small portion of the tunnels and move slowly, so are easily avoided.
Third, every year that the human army doesn't come is an opportunity to build MORE tunnels. The longer you stay, the more entrenched you become. Don't worry about making a secure hole with fortified entries -- instead create as many entrances as you possibly can. Instead of being masters of siege and fortification, become masters of stealth and maze navigation. More tunnels means less chance of getting trapped and better ventilation.
Finally, you now have have more tunnels than you can possibly use. Put them to good use by intruducing vermin and enticing other creatures to lair. Since you know the tunnels you can easily avoid problem areas, but invaders will stumble blindly into lair after lair. Besides, those spiders and shriekers make for good hunting and increase your self-sufficiency. Also, now that you have such a wonderful warren of tunnels, invite other humanoids to join you -- goblins, orcs, who cares? There's room enough for all, and strength in numbers. Form alliances when you can. Better yet, if a really powerful monster moves in nearby, that'll distract the human's attention. Again, you're clever and can just avoid that part of the tunnels.
Oh yes, one last thing: now that you've made yourself hard to catch, be sure to punish any invasion attempt with vengeful raids. Burn fields, eat babies, and make them suffer. Build a reputation for vicious evil and shocking cruelty. Make them fear. When they can't catch you, and every attempt brings pain, sooner or later even the stupidest men will give up and leave you alone.