Personally I wouldn't do it. For me ethics and not harming others takes precedence over money and the social status of a job. Helping the military produce research that can allow them to improve soldiering is part of a casual chain that helps them harm, dominate and kill others.
There is a great book that deals with this: Disciplined Minds: A Critical Look at Salaried Professionals and the Soul-battering System That Shapes Their Lives
. Jeff Schmidt, the author, is a Physics Phd graduate. He says the way that graduate school is set up, if you look to really develop a general knowledge of your field via self study, you will flunk out. What works, especially in his field is learning the mathematical tricks, shortcuts and selective memorization which you will need to pass the heavy burden of testing. What this does is weed out all the inside oriented people who are autonomous, and selects the externally controlled and motivated who will use their degrees to achieve positions of technocratic management. Regarding research, Schmidt states that the military makes freely available what fields or areas it has interest in. He says that those applying for research grants know this, and the successful ones are good at writing proposals that will capture such funding. Another aspect is that these professionals with certified post-graduate degrees like to consider themselves liberal for their "political" opinions. But that is just theoretical, in reality they are highly conservative and tend to lack a sense of compassion or justice that comes from being able to think outside of the system. Their liberalism disappears where they actually have social power, in their work life, there they tend to be very by the book and undemocratic. Ultimately, what he is saying, is that the system certifies professionals and rewards them with more social power in the workplace, more money, because it knows they have the right attitude and ideology to uphold the system, because they cannot think outside of it, they proved that. Such people feel that the world needs better technocratic managers like them wrangling and haggling over technical details, that the "bad" politicians get in their way. They cannot understand that the whole foundation of our civilization is built on greed, gluttony and vices. Unwelcome Guests converted this work into an audiobook available here
You have to ask yourself where your priorities are. For example, in the capitalist governing ethos, humans are said to be selfish beings who only seek to maximize their self-interest and profit at the expense of all and everything. If you felt the situation demanded it and you took an ethical stance that led to leaving that job, most people would ostracize you and not be able to empathize, they cannot understand such a position. The question is if you can live with yourself or not for helping the military do its imperialist work.