All Downloads are FREE. Search and download functionalities are using the official Maven repository.

netflix.nebula.dependency.recommender.RecommendationsOverrideTransitivesStrategy Maven / Gradle / Ivy

Go to download

Allows projects to leave off version numbers in dependencies section and have versions recommended by other sources

The newest version!
package netflix.nebula.dependency.recommender;

import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.DependencyResolveDetails;
import org.gradle.api.artifacts.ModuleVersionSelector;

import java.util.ArrayList;
import java.util.List;

public class RecommendationsOverrideTransitivesStrategy extends RecommendationStrategy {

    private List firstOrderDepsWithVersions = new ArrayList<>();

    @Override
    public void inspectDependency(Dependency dependency) {
        if (dependency.getVersion() != null && !dependency.getVersion().isEmpty()) {
            firstOrderDepsWithVersions.add(dependency.getGroup() + ":" + dependency.getName());
        }
    }

    @Override
    public boolean canRecommendVersion(ModuleVersionSelector selector) {
        String version = selector.getVersion();
        boolean versionMissing = version == null || version.isEmpty();
        return versionMissing || !firstOrderDepsWithVersions.contains(getCoord(selector));
    }

    @Override
    public boolean recommendVersion(DependencyResolveDetails details, String version) {
        if (version == null) {
            return false;
        }
        details.useVersion(version);
        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy