Configuration.getAllDependencies() in plugin

configuration.getAllDependencies() returns resultset when executed from gradle.build via my BuildUtil.groovy but not when same piece of code is in a custom Groovy plugin’s custom task. To address this issue, I moved he apply plugin: ‘buildutils’ after the dependencies {} block but then I get build failure with Failed to apply plugin [id ‘buildutils’]

Do I need to re-resolve dependencies in the plugin? I tried configuration.getResolvedConfiguration()