[ https://issues.apache.org/jira/browse/MRESOLVER-518?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17833491#comment-17833491 ]
ASF GitHub Bot commented on MRESOLVER-518: ------------------------------------------ cstamas commented on code in PR #450: URL: https://github.com/apache/maven-resolver/pull/450#discussion_r1549450171 ########## maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/transformer/ConfigurableVersionSelector.java: ########## @@ -0,0 +1,350 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.eclipse.aether.util.graph.transformer; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +import org.eclipse.aether.RepositoryException; +import org.eclipse.aether.collection.UnsolvableVersionConflictException; +import org.eclipse.aether.graph.DependencyFilter; +import org.eclipse.aether.graph.DependencyNode; +import org.eclipse.aether.util.graph.transformer.ConflictResolver.ConflictContext; +import org.eclipse.aether.util.graph.transformer.ConflictResolver.ConflictItem; +import org.eclipse.aether.util.graph.transformer.ConflictResolver.VersionSelector; +import org.eclipse.aether.util.graph.visitor.PathRecordingDependencyVisitor; +import org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor; +import org.eclipse.aether.version.Version; +import org.eclipse.aether.version.VersionConstraint; + +import static java.util.Objects.requireNonNull; + +/** + * A configurable version selector for use with {@link ConflictResolver} that resolves version conflicts using a + * specified strategy. If there is no single node that satisfies all encountered version ranges, the selector will fail. + * Based on configuration, this selector may fail for other reasons as well. + * + * @since 2.0.0 + */ +public class ConfigurableVersionSelector extends VersionSelector { + /** + * The strategy how "winner" is being selected. + */ + public enum SelectionStrategy { + /** + * This is how Maven3 works, chooses "nearer" dependency for winner. + */ + NEARER, + /** + * This is new mode, chooses "higher version" dependency for winner. + */ + HIGHER_VERSION; + } + /** + * The compatibility check strategy. + */ + public interface CompatibilityStrategy { + /** + * This method should determine are versions of two items "compatible" or not. This method is invoked whenever + * {@code candidate} is "considered" (does not have to be selected as "winner"). + */ + boolean isIncompatibleVersion(ConflictItem candidate, ConflictItem winner) + throws UnsolvableVersionConflictException; + } + /** + * If true, this version selector will fail if detects "dependency version divergence" in graph. + */ + protected final boolean enforceVersionConvergence; Review Comment: Agreed, is a strategy now. > Improvements for version selector > --------------------------------- > > Key: MRESOLVER-518 > URL: https://issues.apache.org/jira/browse/MRESOLVER-518 > Project: Maven Resolver > Issue Type: New Feature > Components: Resolver > Reporter: Tamas Cservenak > Assignee: Tamas Cservenak > Priority: Major > Fix For: 2.0.0, 2.0.0-alpha-11 > > > Currently Resolver "silently" resolves conflict based on "nearest" strategy, > without any assumption about selected version (simply the fact it is "nearer > to root" makes it win). > Extend this logic by ability to fail collection in case of version conflict, > version divergence and "version incompatibility" for start. As it may come > handy, and user may want to fix the build differently than Maven would. -- This message was sent by Atlassian Jira (v8.20.10#820010)