@@ -147,7 +147,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
147147
148148 @ Override
149149 public Xml visitDocument (Xml .Document document , ExecutionContext ctx ) {
150- isNewDependencyPresent = checkIfNewDependencyPresent (newGroupId , newArtifactId , newVersion );
150+ isNewDependencyPresent = checkIfNewDependencyPresents (newGroupId , newArtifactId , newVersion );
151151 if (!oldGroupId .contains ("*" ) && !oldArtifactId .contains ("*" ) &&
152152 (changeManagedDependency == null || changeManagedDependency )) {
153153 doAfterVisit (new ChangeManagedDependencyGroupIdAndArtifactId (
@@ -170,26 +170,16 @@ public Xml visitTag(Xml.Tag tag, ExecutionContext ctx) {
170170 }
171171 boolean isPluginDependency = isPluginDependencyTag (oldGroupId , oldArtifactId );
172172 boolean isAnnotationProcessorPath = isAnnotationProcessorPathTag (oldGroupId , oldArtifactId );
173- boolean deferUpdate = false ;
174173 if (isOldDependencyTag || isPluginDependency || isAnnotationProcessorPath ) {
175- ResolvedPom rp = getResolutionResult ().getPom ();
176174 String groupId = newGroupId ;
177175 if (groupId != null ) {
178- Optional <Xml .Tag > groupIdTag = t .getChild ("groupId" );
179- Optional <String > groupIdValue = t .getChildValue ("groupId" );
180- if (groupIdTag .isPresent () && !groupId .equals (rp .getValue (groupIdValue .orElse (null )))) {
181- t = changeChildTagValue (t , "groupId" , groupId , ctx );
182- }
176+ t = changeChildTagValue (t , "groupId" , groupId , ctx );
183177 } else {
184178 groupId = t .getChildValue ("groupId" ).orElseThrow (NoSuchElementException ::new );
185179 }
186180 String artifactId = newArtifactId ;
187181 if (artifactId != null ) {
188- Optional <Xml .Tag > artifactIdTag = t .getChild ("artifactId" );
189- Optional <String > artifactIdValue = t .getChildValue ("artifactId" );
190- if (artifactIdTag .isPresent () && !artifactId .equals (rp .getValue (artifactIdValue .orElse (null )))) {
191- t = changeChildTagValue (t , "artifactId" , artifactId , ctx );
192- }
182+ t = changeChildTagValue (t , "artifactId" , artifactId , ctx );
193183 } else {
194184 artifactId = t .getChildValue ("artifactId" ).orElseThrow (NoSuchElementException ::new );
195185 }
@@ -202,37 +192,33 @@ public Xml visitTag(Xml.Tag tag, ExecutionContext ctx) {
202192 Scope scope = scopeTag .map (xml -> Scope .fromName (xml .getValue ().orElse ("compile" ))).orElse (Scope .Compile );
203193 Optional <Xml .Tag > versionTag = t .getChild ("version" );
204194
205- boolean configuredToOverrideManagedVersion = overrideManagedVersion != null && overrideManagedVersion ; // False by default
195+ boolean configuredToOverrideManageVersion = overrideManagedVersion != null && overrideManagedVersion ; // False by default
206196 boolean configuredToChangeManagedDependency = changeManagedDependency == null || changeManagedDependency ; // True by default
207197
208198 boolean versionTagPresent = versionTag .isPresent ();
209199 // dependencyManagement does not apply to plugin dependencies or annotation processor paths
210- boolean oldDependencyDefinedManaged = isOldDependencyTag && canAffectManagedDependency ( getResolutionResult (), scope , oldGroupId , oldArtifactId );
200+ boolean oldDependencyManaged = isOldDependencyTag && isDependencyManaged ( scope , oldGroupId , oldArtifactId );
211201 boolean newDependencyManaged = isOldDependencyTag && isDependencyManaged (scope , groupId , artifactId );
212-
213202 if (versionTagPresent ) {
214203 // If the previous dependency had a version but the new artifact is managed, removed the version tag.
215- if (!configuredToOverrideManagedVersion && newDependencyManaged || (oldDependencyDefinedManaged && configuredToChangeManagedDependency )) {
204+ if (!configuredToOverrideManageVersion && newDependencyManaged || (oldDependencyManaged && configuredToChangeManagedDependency )) {
216205 t = (Xml .Tag ) new RemoveContentVisitor <>(versionTag .get (), false , true ).visit (t , ctx );
217206 } else {
218207 // Otherwise, change the version to the new value.
219208 t = changeChildTagValue (t , "version" , resolvedNewVersion , ctx );
220209 }
221- } else if (configuredToOverrideManagedVersion || ( !newDependencyManaged && !( oldDependencyDefinedManaged && configuredToChangeManagedDependency )) ) {
222- // If the version is not present, add the version if we are explicitly overriding a managed version or if no managed version exists.
210+ } else if (configuredToOverrideManageVersion || !newDependencyManaged ) {
211+ //If the version is not present, add the version if we are explicitly overriding a managed version or if no managed version exists.
223212 Xml .Tag newVersionTag = Xml .Tag .build ("<version>" + resolvedNewVersion + "</version>" );
224213 //noinspection ConstantConditions
225214 t = (Xml .Tag ) new AddToTagVisitor <ExecutionContext >(t , newVersionTag , new MavenTagInsertionComparator (t .getChildren ())).visitNonNull (t , ctx , getCursor ().getParent ());
226- } else if (!newDependencyManaged ) {
227- // We leave it up to the managed dependency update to call `maybeUpdateModel()` instead to avoid interim dependency resolution failure
228- deferUpdate = true ;
229215 }
230216 } catch (MavenDownloadingException e ) {
231217 return e .warn (tag );
232218 }
233219 }
234220
235- if (t != tag && ! deferUpdate ) {
221+ if (t != tag ) {
236222 maybeUpdateModel ();
237223 }
238224 }
@@ -241,7 +227,7 @@ public Xml visitTag(Xml.Tag tag, ExecutionContext ctx) {
241227 return t ;
242228 }
243229
244- private boolean checkIfNewDependencyPresent (@ Nullable String groupId , @ Nullable String artifactId , @ Nullable String version ) {
230+ private boolean checkIfNewDependencyPresents (@ Nullable String groupId , @ Nullable String artifactId , @ Nullable String version ) {
245231 if ((groupId == null ) || (artifactId == null )) {
246232 return false ;
247233 }
@@ -262,23 +248,6 @@ private boolean isDependencyManaged(Scope scope, String groupId, String artifact
262248 return false ;
263249 }
264250
265- private boolean canAffectManagedDependency (MavenResolutionResult result , Scope scope , String groupId , String artifactId ) {
266- // We're only going to be able to effect managed dependencies that are either direct or are brought in as direct via a local parent
267- // `ChangeManagedDependencyGroupIdAndArtifactId` cannot manipulate BOM imported managed dependencies nor direct dependencies from remote parents
268- Pom requestedPom = result .getPom ().getRequested ();
269- for (ManagedDependency requestedManagedDependency : requestedPom .getDependencyManagement ()) {
270- if (groupId .equals (requestedManagedDependency .getGroupId ()) && artifactId .equals (requestedManagedDependency .getArtifactId ())) {
271- if (requestedManagedDependency instanceof ManagedDependency .Defined ) {
272- return scope .isInClasspathOf (Scope .fromName (((ManagedDependency .Defined ) requestedManagedDependency ).getScope ()));
273- }
274- }
275- }
276- if (result .parentPomIsProjectPom () && result .getParent () != null ) {
277- return canAffectManagedDependency (result .getParent (), scope , groupId , artifactId );
278- }
279- return false ;
280- }
281-
282251 @ SuppressWarnings ("ConstantConditions" )
283252 private String resolveSemverVersion (ExecutionContext ctx , String groupId , String artifactId , @ Nullable String currentVersion ) throws MavenDownloadingException {
284253 if (versionComparator == null ) {
0 commit comments