Allow specifying custom `gem` to use in gem state and module

Better late than never - here is a PR for issue #13202