Using plugin manager vs plugin container in java plugin

Hi,

In my code I am applying a 3rd party plugin using this syntax:

SpotlessPlugin spotless = project.getPlugins().apply(SpotlessPlugin.class);
spotless.getExtension().java(JavaExtension::removeUnusedImports);
spotless.getExtension().java(j -> j.googleJavaFormat("1.7"));
spotless.getExtension().java(j -> j.targetExclude("build/**"));

However, in the documentation for project.getPlugins() I see that its says:

While not deprecated, it is preferred to use the methods of this interface or the plugin manager than use the plugin container.

Use one of the ‘apply’ methods on this interface or on the plugin manager to apply plugins instead of applying via the plugin container.

Use PluginManager.hasPlugin(String) or similar to query for the application of plugins instead of doing so via the plugin container.

But I see that project.getPluginManager().apply (https://docs.gradle.org/current/javadoc/org/gradle/api/plugins/PluginManager.html#apply-java.lang.Class-) the method returns void so I am not sure how I can configure the plugin after applying it like I am doing in the current code.

I guess I am asking 2 questions:

  1. Is there a way to use pluginManager (the recommended way) and then configure the plugin I applied?
  2. Why plugin.getPlugins() (that returns PluginContainer) is discouraged and not recommended like PluginManager?