If you are a resident in Germany, you have to pass the exam in Germany. UK licenses are valid in Germany, even if you are a resident but you can only acquire one while residing in the UK. The rule is very clear and stems from article 7 of directive 2006/126/EC.
Where things get a little more complex is that in principle, the UK should not issue a license in your situation. So it might seem at first that it would be the UK's responsibility to check that you fulfill the residency requirement and that the German authorities would have to accept any UK licence on its face. But that's not the case!
Even if you do manage to get a UK license while residing in Germany, Germany can in fact still enforce the residency rule itself. There is a provision for that in German law (that's what the text quoted in your comment to another answer is about and it's directly translated from the relevant statute).
Your driving licence does not entitle you to drive or ride a motor vehicle in the Federal Republic of Germany if you, according to the EU or EEA driving licence or incontestable information supplied by the issuing EU Member State or state party to the European Economic Area, had your normal residence in the Federal Republic of Germany at the time the licence was issued.
You will also find language to that effect on countless official websites (as a random example here is one from the city of Bochum).
And it's not a mere theoretical issue, Germany really does care (mostly for German citizens seeking to circumvent driving bans, though) and the issue has been fought in court to the bitter end.
Even if the text of the directive might have seemed a little unclear, the German interpretation has been validated by the EU Court of Justice so it's difficult to argue that German law infringes the directive and that argument won't help you in front of a German court.
I am not a lawyer and I don't know all the nuances of the applicable law but I would think that if you work and live in Germany and are registered at a municipality, you would be deemed a resident and could get some difficulties, especially when trying to renew your license in ten years from now. On the other hand, exchanging your license is not really necessary, at least not before the first one expires.