@@ -92,7 +92,10 @@ def _is_cloud_client(existing_modules: List[module.Module]) -> bool:
92
92
93
93
94
94
def update_cloud_pom (
95
- filename : str , proto_modules : List [module .Module ], grpc_modules : List [module .Module ]
95
+ filename : str ,
96
+ proto_modules : List [module .Module ],
97
+ grpc_modules : List [module .Module ],
98
+ repo_metadata : dict ,
96
99
):
97
100
tree = etree .parse (filename )
98
101
root = tree .getroot ()
@@ -104,6 +107,39 @@ def update_cloud_pom(
104
107
if m .find ("{http://maven.apache.org/POM/4.0.0}artifactId" ) is not None
105
108
]
106
109
110
+ # as of July 2024, we have two dependencies that should be declared as
111
+ # test-scoped: grpc-google-common-protos and grpc-google-iam-v1. Only in
112
+ # java-storage and java-spanner we keep them as they are
113
+ TEST_SCOPED_DEPENDENCIES = ["grpc-google-common-protos" , "grpc-google-iam-v1" ]
114
+ print (
115
+ 'converting old dependencies "grpc-google-common-protos" and "grpc-google-iam-v1" to test-scoped'
116
+ )
117
+ for d in dependencies :
118
+ if repo_metadata ["repo_short" ] in ["java-spanner" , "java-storage" ]:
119
+ print (
120
+ f"skipping test-scoped-dependency fix for special case repo: { repo_metadata ['repo_short' ]} "
121
+ )
122
+ continue
123
+ artifact_query = "{http://maven.apache.org/POM/4.0.0}artifactId"
124
+ scope_query = "{http://maven.apache.org/POM/4.0.0}scope"
125
+ current_scope = d .find (scope_query )
126
+ artifact_id_elem = d .find (artifact_query )
127
+ if artifact_id_elem is None :
128
+ continue
129
+ artifact_id = artifact_id_elem .text
130
+ is_test_scoped = (
131
+ current_scope .text == "test" if current_scope is not None else False
132
+ )
133
+ if artifact_id in TEST_SCOPED_DEPENDENCIES and not is_test_scoped :
134
+ new_scope = etree .Element (scope_query )
135
+ new_scope .text = "test"
136
+ if current_scope is not None :
137
+ d .replace (current_scope , new_scope )
138
+ else :
139
+ d .append (new_scope )
140
+ new_scope .tail = "\n "
141
+ new_scope .getprevious ().tail = "\n "
142
+
107
143
try :
108
144
grpc_index = _find_dependency_index (
109
145
dependencies , "com.google.api.grpc" , "grpc-"
@@ -492,7 +528,9 @@ def main(versions_file, monorepo):
492
528
if os .path .isfile (f"{ artifact_id } /pom.xml" ):
493
529
print ("updating modules in cloud pom.xml" )
494
530
if artifact_id not in excluded_poms_list :
495
- update_cloud_pom (f"{ artifact_id } /pom.xml" , proto_modules , grpc_modules )
531
+ update_cloud_pom (
532
+ f"{ artifact_id } /pom.xml" , proto_modules , grpc_modules , repo_metadata
533
+ )
496
534
elif artifact_id not in excluded_poms_list :
497
535
print ("creating missing cloud pom.xml" )
498
536
templates .render (
0 commit comments