Fixing GPG Error Code 2 on Mac OS

Recently i was trying to publish a new version of my fabricator library. I haven't touched it in a while and it appeared that my setup got a bit outdated. I had to update GPG agent and client, so when i tried to do sbt clean publishSigned i suddenly got GPG Error Code 2 and no other error. After some googling only 1 thing helped me : export GPG_TTY=$(tty). This variable actually makes the promt window in terminal for passphrase to actually show up!. That's why it was failing for me - i was not entering passcode and i couldn't, because window was not visible. Honestly, don't know why this works like this, but i hope it will help other people like me :)