You cannot really do it.
What you actually try is to list all compile dependencies of the actual project, while the compile configuration is long time deprecated and also non-existent by now as you see. classpath also does not work, as on the actual project there is no such configuration and even if it were, it would not contain what you are after. classpath only exists on build script instances by default, but it might also not contain all dependencies you are after.
Iirc, what you probably need to do is to iterate over project.plugins to get the applied plugins and then do some classpath searching, getting the class loader from the plugin class, searching which jar the class comes from to extract the version from the jar name or some similar hackery.