resolveFactoryMethodIfPossible considers nonPublicAccessAllowed and SecurityManager

Issue: SPR-11422
(cherry picked from commit 603cdea)
Polishing

Issue: SPR-11422
(cherry picked from commit 520ef9e)
Actually upgraded to Gradle 1.11