Skip to content

Commit d5d69b4

Browse files
fix: auto-update codeflash-runtime version in user pom.xml
Previously, if codeflash-runtime was already in a user's pom.xml (e.g. from a prior run with 1.0.0), the dependency was left as-is. After a CLI upgrade expecting 1.0.1, Maven would fail to resolve the old version. Now the dependency is always updated to match CODEFLASH_RUNTIME_VERSION, handling both version bumps and the legacy system-scope to test-scope migration in one pass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 325bb80 commit d5d69b4

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

codeflash/languages/java/maven_strategy.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -288,26 +288,26 @@ def add_codeflash_dependency(pom_path: Path) -> bool:
288288
content = pom_path.read_text(encoding="utf-8")
289289

290290
if "codeflash-runtime" in content:
291-
if "<scope>system</scope>" in content:
292-
293-
def replace_system_dep(match: re.Match[str]) -> str:
294-
block: str = match.group(0)
295-
if "codeflash-runtime" in block and "<scope>system</scope>" in block:
296-
return (
297-
"<dependency>\n"
298-
" <groupId>com.codeflash</groupId>\n"
299-
" <artifactId>codeflash-runtime</artifactId>\n"
300-
f" <version>{CODEFLASH_RUNTIME_VERSION}</version>\n"
301-
" <scope>test</scope>\n"
302-
" </dependency>"
303-
)
291+
292+
def update_codeflash_dep(match: re.Match[str]) -> str:
293+
block: str = match.group(0)
294+
if "codeflash-runtime" not in block:
304295
return block
296+
return (
297+
"<dependency>\n"
298+
" <groupId>com.codeflash</groupId>\n"
299+
" <artifactId>codeflash-runtime</artifactId>\n"
300+
f" <version>{CODEFLASH_RUNTIME_VERSION}</version>\n"
301+
" <scope>test</scope>\n"
302+
" </dependency>"
303+
)
305304

306-
content = re.sub(r"<dependency>[\s\S]*?</dependency>", replace_system_dep, content)
307-
pom_path.write_text(content, encoding="utf-8")
308-
logger.info("Replaced system-scope codeflash-runtime dependency with test scope")
309-
return True
310-
logger.info("codeflash-runtime dependency already present in pom.xml")
305+
updated = re.sub(r"<dependency>[\s\S]*?</dependency>", update_codeflash_dep, content)
306+
if updated != content:
307+
pom_path.write_text(updated, encoding="utf-8")
308+
logger.info("Updated codeflash-runtime dependency to version %s in pom.xml", CODEFLASH_RUNTIME_VERSION)
309+
else:
310+
logger.info("codeflash-runtime dependency already up to date in pom.xml")
311311
return True
312312

313313
closing_tag = "</dependencies>"

0 commit comments

Comments
 (0)