If you really love her and think that other girls can't get into your eyes, you are not as good as her, so stay with her as a good friend. Although you are with him as a good friend, she will know you better during this time. If one day she breaks up with her boyfriend, you may not have a chance, but please remember to be brave and take the initiative this time.
Personally, I think you should give up your love for her. After all, twisting melons is not sweet. Since he already has a boyfriend, it means that he has no feelings for you, so why do you insist on making yourself unhappy? In fact, there are many girls who are better than him in the world. You are only upset because you have spent so many years on her. You even regret that you didn't have the courage to tell her.
I suggest that you spend all your energy on your study. There are so many excellent girls in the university, there will definitely be one who is more suitable for you. If you are depressed about your studies because of a girl, it's really not worth it. You know, being outstanding is like not liking your own girl. Most of the time, only by getting to know more people in a bigger environment can you have more chances to find a more suitable partner, so don't worry that he already has a boyfriend, put down his energy and spend his time on work and study. Only when you become better will more people admire you.