@@ -241,6 +241,31 @@ def modernize_pom(file_path, parent_version, source_repo_name=None, parent_artif
241241 continue
242242 if '</dependency>' in line :
243243 in_dependency = False
244+
245+ # Monorepo version alignment and annotation
246+ if monorepo_versions and current_artifact_id and current_artifact_id in monorepo_versions :
247+ new_version = monorepo_versions [current_artifact_id ]
248+ marker_artifact = current_artifact_id .replace ('-bom' , '' )
249+ annotation = f"<!-- {{x-version-update:{ marker_artifact } :current}} -->"
250+ version_line_content = f"<version>{ new_version } </version>{ annotation } \n "
251+
252+ if has_version :
253+ # Replace existing version line
254+ for i , d_line in enumerate (current_dependency_lines ):
255+ if '<version>' in d_line :
256+ indent = d_line [:d_line .find ('<' )]
257+ current_dependency_lines [i ] = f"{ indent } { version_line_content } "
258+ break
259+ else :
260+ # Add missing version line before </dependency>
261+ indent = " " # Default indent
262+ if len (current_dependency_lines ) > 0 :
263+ first_line = current_dependency_lines [0 ]
264+ indent = first_line [:first_line .find ('<' )] + " "
265+ current_dependency_lines .append (f"{ indent } { version_line_content } " )
266+
267+ should_preserve = True
268+
244269 current_dependency_lines .append (line )
245270
246271 if current_artifact_id == 'google-cloud-shared-dependencies' :
@@ -269,6 +294,10 @@ def modernize_pom(file_path, parent_version, source_repo_name=None, parent_artif
269294 is_external = current_group_id and not current_group_id .startswith ('com.google' )
270295 is_google_cloud_lib = current_group_id == 'com.google.cloud' and current_artifact_id and current_artifact_id .startswith ('google-cloud-' )
271296
297+ # Skip gapic-libraries-bom in dependencyManagement
298+ if in_dep_mgmt and current_artifact_id == 'gapic-libraries-bom' :
299+ continue
300+
272301 if not in_dep_mgmt or should_preserve or (is_external and has_version ) or (is_google_cloud_lib and has_version ):
273302 new_lines .extend (current_dependency_lines )
274303 continue
@@ -285,15 +314,6 @@ def modernize_pom(file_path, parent_version, source_repo_name=None, parent_artif
285314 if '<version>' in line :
286315 has_version = True
287316
288- if monorepo_versions and current_artifact_id and current_artifact_id in monorepo_versions :
289- new_version = monorepo_versions [current_artifact_id ]
290- indent = line [:line .find ('<' )]
291- if '<version>' in line :
292- marker_artifact = current_artifact_id .replace ('-bom' , '' )
293- current_dependency_lines .append (f"{ indent } <version>{ new_version } </version><!-- {{x-version-update:{ marker_artifact } :current}} -->\n " )
294- should_preserve = True
295- continue
296-
297317 if current_artifact_id and current_artifact_id .startswith ('google-api-services-' ):
298318 should_preserve = True
299319
0 commit comments