A repeatable pipeline for upgrading Mule 4.3 applications to Mule 4.9 on Java 17 using an AI assistant (Claude Code, Agentforce, optional MCP server) for the rote edits: discovery, pom and connector upgrades, DataWeave fixes, MUnit generation. Humans gate the result with a scripted verification gate (JDK 17 build, MUnit, deprecated-pattern grep, runtime start-up check, golden-response parity) and a rehearsed blue-green cutover and rollback. Includes a real before/after pom diff and the behaviour drifts AI assistants introduce during migrations.
Tags: ci-cd, mcp, mule-4, claude-code, java-17, blue-green, munit, dataweave, agentforce, connector-upgrade, maven, mule-migration
Mule 4.3 to 4.9 AI-Assisted Migration: Rote Edits by the Model, Gates by Deterministic Checks
Deliverable: A repeatable migration pipeline that takes each Mule 4.3 application to Mule 4.9 on Java 17: an AI-generated discovery report, a reviewed per-app migration branch (pom, connectors, DataWeave, MUnit), a scripted verification gate that decides pass or fail, and a blue-green cutover with a tested rollback.
Objective: Mule 4.3 estates stay put because migration looks like weeks of mechanical edits across dozens of apps: runtime and plugin versions, connector upgrades, Java 17 incompatibilities, DataWeave fixes, and tests nobody wrote. AI assistants (Claude Code, Agentforce, an MCP server for the runtime) are good at exactly that rote work, and bad at knowing when they have quietly changed behaviour. Working looks like this: the AI proposes every edit, but nothing merges unless a build, the MUnit suite, a runtime start-up check and a diff review all pass. Humans gate the result; the model never grades its own work.
What's Getting Built
- Discovery report (analysis step, run by the AI assistant) — per app: Mule version, connector versions, Java 17 risk in custom code, a complexity-ranked priority matrix ·
mvn dependency:tree, rg inventory commands
- Per-app migration branch (AI edits, human review) —
pom.xml runtime, plugin and connector bumps, DataWeave and error-handling fixes, regenerated MUnit suite · one Git branch per app
- Verification gate (deterministic script, CI) — Java 17 build, MUnit run, deprecated-pattern grep, runtime start-up check ·
mvn clean package, mvn test, rg, GET /api/health (your app's health endpoint)
- Side-by-side runtimes (blue = 4.3 on Java 8 or 11, green = 4.9 on Java 17) — cutover and rollback by stopping one and starting the other ·
mule start, mule stop
Prerequisites
- Java 8 or 11 for the 4.3 runtime and Java 17 LTS for 4.9. Both JDKs can coexist on one host; set
JAVA_HOME per runtime, never globally.
- A Mule 4.3 runtime and a Mule 4.9 runtime installed side by side (standalone), or non-production environments of both on your target platform. Pin the exact 4.9 patch version in the pom and confirm it against the current release notes.
- Maven 3.8 or later, Git, and Anypoint Code Builder or VS Code with the MuleSoft extensions. Node.js 20 or later only if you run an MCP server for the assistant.
- Credentials for the Exchange Maven repository in Maven
settings.xml, never in the pom.
- Access to non-production backends for every connector (database, Salesforce and so on). MUnit with mocks proves routing and mapping, not connectivity, so each app needs one real-endpoint smoke test.
- Agreement from app owners on what "same behaviour" means: response shapes, status codes, schedules. This is the contract the gate protects, and it takes longer to get than the edits take to write.
- A backup of every deployed 4.3 application archive before you touch anything.
- AI assistant access scoped to a working copy. Secrets stay in environment variables; do not paste property values, passwords or tokens into prompts.
Choose your path
- In-place branch per app — Choose this when each app has a Git repo and CI. The AI edits a branch, the gate runs on the pull request, a human merges. This is the default.
- Archive-based migration — Choose this when apps exist only as deployed archives on a runtime. Unzip each archive into a working directory and commit it to a new repo first. Do not start editing until the source is under version control, because without a diff you cannot review what the AI changed.
Architecture
1. Inventory and discovery
- Put every app under Git first. Record the Mule runtime version, each connector and its version, and any custom Java classes.
mvn dependency:tree per app gives connector versions without trusting the model's reading.
- Have the assistant produce the report from the real files, with a prompt shaped like: for each application, identify the Mule and connector versions; check compatibility with Mule 4.9 and Java 17; flag custom Java that may break under strong encapsulation (reflection,
sun.misc.Unsafe); rank apps by complexity; output a compatibility report. Require it to cite file and line for each finding so a human can spot-check.
- Migrate a low-complexity app first and use it to tune your prompts. Business-critical apps go last.
2. Pin the target toolchain
- Change versions in the pom in one reviewable commit before any flow edits: the runtime property, the Mule Maven plugin, the MUnit version, the compiler level (17), and each connector. When an app has many connectors, upgrade one at a time so a resolution failure points at one dependency.
- Take target versions from each connector's Exchange page or the current release notes, not from the model's memory. A version the assistant "remembers" can be wrong or unpublished; the build is the judge.
- Move the Exchange Maven repository entry to the v3 endpoint. Declare JDBC drivers as normal dependencies and list them under
sharedLibraries in the Mule Maven plugin configuration.
3. Let the AI do the rote edits, with a narrow brief
- Prompt shape that works: project path, target runtime and Java version, then a numbered task list: update pom versions, upgrade connectors to Java 17 compatible versions, fix DataWeave that fails to compile, update error handling, add the validation module if absent, generate MUnit tests. Add an explicit limit: do not change response shapes, status codes, SQL semantics, schedules or business logic.
- That limit matters. Unconstrained assistants "improve" things during a migration. Typical drifts: a date format string rewritten (changing the API's output contract),
SELECT * replaced by a column list plus a LIMIT, a scheduler frequency changed, new endpoints added, comments that claim a feature (such as OAuth) the config does not use. Each is a behaviour change nobody asked for.
- Ask the assistant to end with a change list grouped as "required for 4.9" and "optional improvement". Reject the second group, or move it to a separate pull request.
4. Verify with deterministic gates
- The gate is a script in the repo, not a prompt. It runs on JDK 17 and fails closed: any non-zero step, unparseable output, or missing test report is a fail. Details are under Deterministic checks.
- Never accept an AI-written test suite on trust. Confirm it parses, confirm each test asserts something that would fail if behaviour regressed, and confirm expected values come from the 4.3 app's recorded responses, not from whatever the new code returns.
- Before migrating, capture golden responses from the running 4.3 app for every endpoint (status, headers, body) and assert the migrated app matches them.
5. Java 17 fixes for custom code
- Strong encapsulation breaks reflective access to JDK internals. Give the assistant the exact stack trace, not a paraphrase, and ask for a replacement using supported APIs. Add
--add-opens JVM arguments to the runtime wrapper config only as a last resort, scoped to the packages that need them, with the reason recorded.
- Recompile custom modules at Java 17 compiler level. A
UnsupportedClassVersionError means classes were built for a newer JVM than the one running them; check which JAVA_HOME the runtime used.
6. Blue-green cutover and rollback
- Leave the 4.3 runtime (blue) running untouched. Start 4.9 (green) with the migrated archives, wait, then call a health endpoint and abort on any non-2xx. Only then switch the proxy or load balancer and stop blue.
- Script the rollback (stop green, start blue, verify health) and rehearse it in non-production. A rollback never exercised is a hope, not a plan.
- On CloudHub 2.0 or Runtime Fabric, blue-green means deploying the migrated app as a second application and switching traffic at the load balancer or API gateway, not stopping and starting runtimes. Keep the 4.3 deployment until the soak period ends.
- Heap and JVM settings differ between runtimes. Size 4.9 from measured load and compare against the 4.3 baseline before cutover.
7. Security and compliance
- Secrets stay in environment variables, a secure configuration properties file, or your secrets manager. The migration branch must contain no real property values; commit a properties template with names only and add a secret scan to the gate.
- Do not send customer data or production payloads to an external model. Use anonymised or synthetic fixtures in prompts and check your data-handling policy before pasting logs, which often contain payloads.
- Keep an audit trail per change set: the prompt, the diff, the gate result and the human approver. Log correlation IDs at INFO; never log credentials or full payloads of regulated data.
- Treat connector upgrades as supply-chain changes: resolve only from your approved Maven repositories.
Sample payload — pom.xml before and after (trimmed)
Illustrative versions only. Confirm every version against the current release notes and each connector's Exchange page, and decide whether you target the 4.9 LTS or Edge release channel.
- <app.runtime>4.3.0</app.runtime>
- <mule.maven.plugin.version>3.5.2</mule.maven.plugin.version>
- <munit.version>2.3.5</munit.version>
+ <app.runtime>4.9.0</app.runtime>
+ <mule.maven.plugin.version>4.3.0</mule.maven.plugin.version>
+ <munit.version>3.2.0</munit.version>
+ <maven.compiler.source>17</maven.compiler.source>
+ <maven.compiler.target>17</maven.compiler.target>
mule-http-connector 1.5.25 -> 1.9.0
mule-sockets-connector 1.2.2 -> 1.2.4
mule-db-connector 1.9.4 -> 1.14.6
mule-salesforce-connector 10.11.0 -> 10.17.0
+mule-secure-configuration-property-module 1.2.5 (new)
+mule-validation-module 2.0.4 (new)
+postgresql (JDBC driver) 42.5.1 (new, plus sharedLibrary entry)
- <id>anypoint-exchange-v2</id>
- <url>https://maven.anypoint.mulesoft.com/api/v2/maven</url>
+ <id>anypoint-exchange-v3</id>
+ <url>https://maven.anypoint.mulesoft.com/api/v3/maven</url>
A behaviour drift of the kind the review must catch, from the same app's flow:
-created: $.CREATED_DATE as String {format: "yyyy-MM-dd"},
+created: $.created_date as String {format: "yyyy-MM-dd'T'HH:mm:ss'Z'"},
That is a changed API output format and a changed column name, not a 4.9 requirement.
Deterministic checks
- Build on Java 17: with
JAVA_HOME at JDK 17, mvn clean package exits 0 and produces the Mule application archive. Any connector resolution failure fails the gate.
- Versions pinned:
rg -n "app.runtime|munit.version|mule.maven.plugin.version|maven.compiler" pom.xml shows the target runtime, compiler level 17, and no 4.3-era values. rg -n "api/v2/maven" pom.xml returns nothing.
- Deprecated and risky patterns:
rg -n "sun\.misc\.Unsafe|setAccessible\(|illegal-access" src returns nothing, or only lines in a reviewed exceptions file. Also compare connector versions in the pom to your approved matrix.
- MUnit:
mvn test passes with no test skipped, at least one test per flow, and coverage at or above the threshold your team sets. The guide behind this blueprint targets a pass rate above 95 percent; treat that as a floor, not a substitute for golden-response comparison.
- Runtime start: deploy the archive to a 4.9 runtime on Java 17. The log shows the application deployed with no
IllegalAccessError, UnsupportedClassVersionError or unresolved plugin, and GET /api/health (your app's health endpoint) returns 200. Read the runtime version from the start-up banner in the log, not from the pom.
- Contract parity: for each endpoint, status code and body schema match the recorded 4.3 golden response. A diff outside an allowed list (timestamps, correlation IDs) fails.
- No secrets: a secret scan over the branch finds no credential values.
Testing and validation
- Happy path: run the golden-response suite against the app on Mule 4.9 using a real non-production database and CRM sandbox, once per app.
- The edge case that breaks naive migrations: the AI-generated MUnit suite itself is invalid or vacuous. Generated test files can be malformed XML, reference configs that do not exist, or mock the very operation they claim to test. If the suite does not parse, the gate must fail rather than report zero tests run. Inject a deliberate regression (change a status code) and confirm the suite goes red.
- Error paths: simulate a database outage and a CRM connectivity failure. Assert the mapped error type and the HTTP status the client actually receives. Setting a variable named
httpStatus has no effect unless the listener's error response reads it.
- Scheduled and batch flows: assert schedule, block size and record counts against the 4.3 values, since a model may retune them silently.
- Performance: run the same load against 4.3 and 4.9 and compare latency and heap with the baseline captured before migration.
Phased rollout
Phase 1 — Connect
- Install both runtimes and both JDKs; prove each starts under the right Java. Point the assistant (and optional MCP server) at a scratch copy. Run discovery on the full inventory and produce the priority matrix.
Phase 2 — Map and validate
- Migrate one simple app end to end through the gate. Tune the prompt until the "required versus optional" change list is clean. Then migrate the rest in complexity order, one branch and one review per app.
Phase 3 — Production
- Deploy to non-production on 4.9, rehearse rollback, then cut over app by app via blue-green. Keep blue available for a defined soak period and decommission only after sign-off. Update runbooks.
Success metrics
- Apps migrated through the gate per week, and the share that passed on first attempt.
- Unrequested behaviour changes caught in review per app (should trend to zero as the prompt tightens).
- Post-cutover error rate and p95 latency against the 4.3 baseline; incidents attributable to the migration.
- Share of the estate still on 4.3, and the date it reaches zero.
Troubleshooting
UnsupportedClassVersionError at start-up — Likely cause: classes compiled for a newer Java than the JVM running the runtime, or the runtime launched with the wrong JAVA_HOME. Fix: check the Java path in the runtime wrapper config and recompile at the right compiler level.
IllegalAccessError or reflective access errors on Java 17 — Likely cause: custom code reaching into JDK internals. Fix: replace with supported APIs; if unavoidable, add a scoped --add-opens argument and document it.
Could not find artifact for a connector — Likely cause: that version is not in your repositories or targets another runtime. Fix: pick a version from the connector's Exchange page, confirm repository credentials, upgrade one connector at a time.
- DataWeave compile error after upgrade — Likely cause: a function or signature changed. Fix: give the assistant the exact error and script, ask for the minimal change, then re-run the golden-response tests.
- MUnit run reports zero tests or fails to load — Likely cause: malformed generated suite or missing config references. Fix: validate the XML, regenerate narrowly per flow, and make the gate fail on zero tests.
- Tests pass but a client sees different output — Likely cause: an AI "improvement" changed a format or query. Fix: add the golden-response assertion and move optional changes to a separate pull request.
PKIX path building failed after moving runtimes — Likely cause: the Java 17 trust store lacks your CA. Fix: import the certificate into the trust store the runtime uses.
- Health check fails after cutover — Likely cause: properties missing on the green host, or backend allow-lists. Fix: run the rollback script, compare property names between hosts, retry.