How else can you get a bunch of kids to have as a life long dream to kill and be killed? You make it look cool and glamorous and hide the nasty bits. If war movies were real they'd all end up with your team half dead in combat and the other half committing suicide back at home from the PTSD.
[0] https://en.wikipedia.org/wiki/Military%E2%80%93entertainment...
What? And that is not controversial?
It's marketing.
And the number bandied about in the first few links was something like $5.5 million over three years. Not a huge amount of money.
If the trades advertised as much as the military there wouldn't be shortages of electricians, plumbers, HVAC technicians, etc. Some of those careers are just as highly technical as programming and might pay just as much (sans stock options). Hollywood doesn't make movies about plumbers though.
[0] https://www.thesoldiersproject.org/what-percentage-of-the-mi...