Every time a software developer leaves a job, I always ask them why they left. I do this because I like the software developers who work with me, and I really don't want them to leave.
Every time I have this conversation, I'm surprised at the wide variety of reasons why developers leave. Most, however, leave for the following two reasons:
1) They are bored with what they are doing.
2) They don't like their new manager, or there was a change in leadership and they didn't like it.
I always expect them to say "I left for more money" or "I left because I hated the company." I hear those reasons after layoffs or firings, but I hardly ever hear those reasons because someone quit.
As software development leaders, it is important that we address those two issues.
The first one is easily solved. Keep your software project fresh, using new technology, and keep your company competitive by always pushing the envelope. This will benefit the developers and keep the company profitable and current.
The second one is a lot tougher. I wish I could answer how to be a good leader in one short blog post. I am writing a book on the topic, where I will go into more depth and provide more information.
I think one thing that covers a lot of what software developers like in a manager is as follows:
1) Shield the developers from the chaos of the business. Don't tell them stories about how there is so much change in the organization and no one knows what they want. Don't confide your troubles in them. Don't blame others when projects get cancelled. Stay positive.
2) Give clear direction on what they need to do in order to be successful. They shouldn't have to guess on what their top three priorities are and what order they are in.
3) Hold them accountable. If you remember what you asked them to do, and you check in on them and how they are doing, you are not micromanaging them. You are actually showing them that what they are working on is important and that you care about them. You are showing them how to be successful and worth all that money you are paying them.
4) Tell them what they have to do to earn more money. Give them a way to earn money from you and not all their side projects. If they don't have a way to increase their income with you, they will start taking work from other sources and they won't talk to you about it.
This is just the reality in an industry where 100% of the good developers have jobs and never have a problem finding more work.
This post doesn't give all the answers, but if you are struggling on how to keep your top talent, minimally addressing these things will go a long way in helping you with that goal.