protected String resolvePluginVersion()

in src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java [520:580]


    protected String resolvePluginVersion(
            ReportPlugin reportPlugin, MavenReportExecutorRequest mavenReportExecutorRequest)
            throws PluginVersionResolutionException {
        String reportPluginKey = reportPlugin.getGroupId() + ':' + reportPlugin.getArtifactId();
        LOGGER.debug("Resolving version for {}", reportPluginKey);

        // look for version defined in the reportPlugin configuration
        if (reportPlugin.getVersion() != null) {
            LOGGER.debug(
                    "Resolved {} version from the reporting.plugins section: {}",
                    reportPluginKey,
                    reportPlugin.getVersion());
            return reportPlugin.getVersion();
        }

        MavenProject project = mavenReportExecutorRequest.getProject();

        // search in the build section
        if (project.getBuild() != null) {
            Plugin plugin = find(reportPlugin, project.getBuild().getPlugins());

            if (plugin != null && plugin.getVersion() != null) {
                LOGGER.debug(
                        "Resolved {} version from the build.plugins section: {}", reportPluginKey, plugin.getVersion());
                return plugin.getVersion();
            }
        }

        // search in pluginManagement section
        if (project.getBuild() != null && project.getBuild().getPluginManagement() != null) {
            Plugin plugin =
                    find(reportPlugin, project.getBuild().getPluginManagement().getPlugins());

            if (plugin != null && plugin.getVersion() != null) {
                LOGGER.debug(
                        "Resolved {} version from the build.pluginManagement.plugins section: {}",
                        reportPluginKey,
                        plugin.getVersion());
                return plugin.getVersion();
            }
        }

        LOGGER.warn("Report plugin {} has an empty version.", reportPluginKey);
        LOGGER.warn("");
        LOGGER.warn("It is highly recommended to fix these problems"
                + " because they threaten the stability of your build.");
        LOGGER.warn("");
        LOGGER.warn("For this reason, future Maven versions might no"
                + " longer support building such malformed projects.");

        Plugin plugin = new Plugin();
        plugin.setGroupId(reportPlugin.getGroupId());
        plugin.setArtifactId(reportPlugin.getArtifactId());

        PluginVersionRequest pluginVersionRequest =
                new DefaultPluginVersionRequest(plugin, mavenReportExecutorRequest.getMavenSession());

        PluginVersionResult result = pluginVersionResolver.resolve(pluginVersionRequest);
        LOGGER.debug("Resolved {} version from repository: {}", reportPluginKey, result.getVersion());
        return result.getVersion();
    }