In a comparative task, you need to define the terms of the question. So here you need to consider what is meant by a 'hero'. Is it the character who is central to the plot of the novel? Does it imply a judgment on their goodness? Does it suggest someone conventionally handsome - a romantic hero?
Gabriel first proposes to Bathsheba early in the novel. He is disarmingly frank in his courtship, and genuinely attracted to Bathsheba, though taken aback by her behaviour, which seems to encourage and then reject him. He then spends much of the novel observing, assisting, and occasionally reprimanding Bathsheba from his new position as lowly shepherd on Bathsheba's estate. His quiet yet unswerving honesty, his practicality and patience, win him the heroine in the end. He is a capable, virtuous hero, not without passion.
Troy is in the mould of the dashing, unscrupulous hero of romantic fiction. He woos Bathsheba with arrogant assurance in his own personal magnetism. The scene with the sword fight is rife with sexual tension. But his abandonment of Bathsheba, his profligacy and degenerate nature, make it hard to see him as the hero. In the end, it is the resurgence of his feelings for Fanny, too late to save her, that makes us respond to him with a degree of pathos.
Boldwood is the older, powerful bachelor, distant and remote until changed forever by the thoughtless action of Bathsheba's valentine. He becomes a tragic figure, though not, I'd say, the hero.
The protagonist is the main character on which our chief interest in the novel focuses. If the protagonist is pitted against another character, he or she is the antagonist. A character whose distinctive feature is to underline another's characteristics my serve as a foil to him or to her. The protagonist is also called a hero or a heroine. Surely, the protagonist or the heroine is Bathsheba. The two male characters called Boldwood and Troy are antagonists. They are inverted figures. They meet their fate during the ultimate confrontation in Boldwood's house.
At the end, interestingly enough, with the final marriage, the roles are reversed since Gabriel, who used to present affinities with Boldwood and oddly enough serve as a foil to him, is made to triumph over his two former rivals ( or friend as regards Boldwood).
The role of the three men is conspicuous. Their role is to play satellite to the star Bathsheba. We must resort to other words than "hero" to designate those three male characters.