Rake.application may be undefined when Rake is defined.

The code expects that as soon as Rake module is defined, Rake.application is defined too.  But this may not be true.
E.g. RubyMine's loggers are defined under Rake::TeamCity module and so Rake module is defined, but Rake.application isn't.