com.lewisd.maven.lint.rules.basic.RedundantDependencyVersionsRule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lint-maven-plugin Show documentation
Show all versions of lint-maven-plugin Show documentation
Generates a report of suspicious/inconsistent POM elements, and optionally fails the build if violations are found.
The newest version!
package com.lewisd.maven.lint.rules.basic;
import com.lewisd.maven.lint.ResultCollector;
import com.lewisd.maven.lint.model.ExtDependency;
import com.lewisd.maven.lint.model.ObjectWithPath;
import com.lewisd.maven.lint.rules.AbstractReduntantVersionRule;
import com.lewisd.maven.lint.util.ExpressionEvaluator;
import com.lewisd.maven.lint.util.ModelUtil;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.PluginParameterExpressionEvaluator;
import org.apache.maven.project.MavenProject;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Collection;
import java.util.Map;
public class RedundantDependencyVersionsRule extends AbstractReduntantVersionRule {
@Autowired
public RedundantDependencyVersionsRule(ExpressionEvaluator expressionEvaluator,
ModelUtil modelUtil,
PluginParameterExpressionEvaluator pluginParameterExpressionEvaluator) {
super(expressionEvaluator, modelUtil, pluginParameterExpressionEvaluator);
}
@Override
public String getIdentifier() {
return "RedundantDepVersion";
}
@Override
public String getDescription() {
return "Dependency versions should be set in one place, and not overridden without changing the version. " +
"If, for example, sets a version, and somewhere overrides it, " +
"but with the same version, this can make version upgrades more difficult, due to the repetition.";
}
@Override
public void invoke(final MavenProject mavenProject, final Map models, final ResultCollector resultCollector) {
final Model originalModel = mavenProject.getOriginalModel();
final Collection dependencies = expressionEvaluator.getPath(originalModel, "dependencies");
final Collection managedDependencies = expressionEvaluator.getPath(originalModel, "dependencyManagement/dependencies");
final Map managedDependenciesByManagementKey = modelUtil.mapByManagementKey(managedDependencies);
for (final Dependency dependency : dependencies) {
final Dependency managedDependency = managedDependenciesByManagementKey.get(dependency.getManagementKey());
if (managedDependency != null) {
checkForRedundantVersions(mavenProject, resultCollector,
new ObjectWithPath
© 2015 - 2025 Weber Informatics LLC | Privacy Policy