Require 'rails_env' task only when needed

Backport of https://github.com/rails/rails/commit/4b8b8c1b4d1b516a9ebf8e19d5a14956c5654ac8

/cc @rudle