diff --git a/maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/LockFileFacade.java b/maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/LockFileFacade.java index 6165e8eba..a908159bb 100644 --- a/maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/LockFileFacade.java +++ b/maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/LockFileFacade.java @@ -22,6 +22,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Plugin; import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuilder; @@ -125,11 +126,25 @@ private static Set getAllPlugins( DependencyCollectorBuilder dependencyCollectorBuilder, AbstractChecksumCalculator checksumCalculator) { Set plugins = new TreeSet<>(Comparator.comparing(MavenPlugin::getChecksum)); + Map pluginConfigMap = new HashMap<>(); + if (project.getBuild() != null && project.getBuild().getPlugins() != null) { + pluginConfigMap = project.getBuild().getPlugins().stream() + .collect(Collectors.toMap(p -> p.getGroupId() + ":" + p.getArtifactId(), p -> p)); + } + for (Artifact pluginArtifact : project.getPluginArtifacts()) { + String key = pluginArtifact.getGroupId() + ":" + pluginArtifact.getArtifactId(); + Plugin pluginConfig = pluginConfigMap.get(key); + RepositoryInformation repositoryInformation = checksumCalculator.getPluginResolvedField(pluginArtifact); Set pluginDependencies = resolvePluginDependencies( - pluginArtifact, session, project, dependencyCollectorBuilder, checksumCalculator); + pluginArtifact, + pluginConfig, + session, + project, + dependencyCollectorBuilder, + checksumCalculator); plugins.add(new MavenPlugin( GroupId.of(pluginArtifact.getGroupId()), ArtifactId.of(pluginArtifact.getArtifactId()), @@ -147,6 +162,7 @@ private static Set getAllPlugins( * Resolve the dependencies of a Maven plugin. * * @param pluginArtifact The plugin artifact to resolve dependencies for + * @param pluginConfig The plugin configuration from the project POM (may be null) * @param session The Maven session * @param project The current Maven project (for repository configuration) * @param dependencyCollectorBuilder The dependency collector builder @@ -155,6 +171,7 @@ private static Set getAllPlugins( */ private static Set resolvePluginDependencies( Artifact pluginArtifact, + Plugin pluginConfig, MavenSession session, MavenProject project, DependencyCollectorBuilder dependencyCollectorBuilder, @@ -267,6 +284,13 @@ private static Set return Collections.emptySet(); } + // Use plugin dependencies from project POM if declared + if (pluginConfig != null + && pluginConfig.getDependencies() != null + && !pluginConfig.getDependencies().isEmpty()) { + pluginProject.setDependencies(pluginConfig.getDependencies()); + } + int declaredDeps = pluginProject.getDependencies() != null ? pluginProject.getDependencies().size() : 0; @@ -302,6 +326,8 @@ private static Set // Get root dependency nodes (excluding the plugin project itself) Set roots = dependencyGraph.getRoots(); + roots = filterPluginDependencyScopes(roots); + PluginLogManager.getLog() .info(String.format("Resolved %4d dependencies for plugin %s", roots.size(), pluginArtifact)); return roots; @@ -313,6 +339,20 @@ private static Set } } + /** + * Filters plugin dependencies to only include valid scopes (compile, runtime, system). + */ + private static Set filterPluginDependencyScopes( + Set dependencies) { + return dependencies.stream() + .filter(dep -> { + String scope = dep.getScope().getValue(); + return scope.equals("compile") || scope.equals("runtime") || scope.equals("system"); + }) + .collect(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing( + io.github.chains_project.maven_lockfile.graph.DependencyNode::getComparatorString)))); + } + private static DependencyGraph graph( MavenSession session, MavenProject project,