Add ai-21-migration module: upgrading Spring AI 2.0.x to 2.1.0, measured. One probe source tree run on 2.0.0, 2.0.2, 2.0.3 and 2.1.0 (Anthropic prompt tokens with caching, auth header, discarded temperature, thinking parts, message mutability, entity() on refusals), three compile breaks, API and configuration diffs from the jars, ChatMemory to session copy, a wrapping ToolCallingManager under tool confirmation, the OpenAI Responses switch, VectorStore.upsert on real pgvector, a grep checklist and an OpenRewrite recipe. Scripted and local fake models; no provider called. Spring Boot 4.2.0, Spring AI 2.1.0, Java 25.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b7N4ZDbUtA3ofqAqRV
This commit is contained in:
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
# Public API and configuration-property differences between two Spring AI releases.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
old=${1:-2.0.3}; new=${2:-2.1.0}
|
||||
scripts/fetch-jars.sh "$old"; scripts/fetch-jars.sh "$new"
|
||||
java tools/ApiDiff.java "jars-cache/$old" "jars-cache/$new" | sed "1i # public API, Spring AI $old -> $new (tools/ApiDiff.java over every non-starter jar in the BOM)" > output/13-api-diff.txt
|
||||
{ echo "# configuration metadata, Spring AI $old -> $new"; python3 -I scripts/config-diff.py "jars-cache/$old" "jars-cache/$new"; } > output/14-config-diff.txt
|
||||
echo "wrote output/13-api-diff.txt and output/14-config-diff.txt"
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
# Artifacts and a few dependency versions: Spring AI 2.0.0, 2.0.3 and 2.1.0.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
mkdir -p target/bom
|
||||
for v in 2.0.0 2.0.3 2.1.0; do
|
||||
curl -s -f --retry 5 "https://repo1.maven.org/maven2/org/springframework/ai/spring-ai-bom/$v/spring-ai-bom-$v.pom" -o "target/bom/$v.pom"
|
||||
sed -n 's:.*<artifactId>\(spring-ai-[^<]*\)</artifactId>.*:\1:p' "target/bom/$v.pom" | sort -u | grep -v '^spring-ai-bom$' > "target/bom/$v.txt"
|
||||
curl -s -f --retry 5 "https://raw.githubusercontent.com/spring-projects/spring-ai/v$v/pom.xml" -o "target/bom/$v.root.xml"
|
||||
done
|
||||
{
|
||||
echo "# spring-ai-bom: managed artifacts"
|
||||
for v in 2.0.0 2.0.3 2.1.0; do echo "$v: $(wc -l < target/bom/$v.txt)"; done
|
||||
echo; echo "in 2.0.3 but not 2.1.0:"; comm -23 target/bom/2.0.3.txt target/bom/2.1.0.txt | sed 's/^/ /'
|
||||
echo; echo "new in 2.1.0 compared with 2.0.3:"; comm -13 target/bom/2.0.3.txt target/bom/2.1.0.txt | sed 's/^/ /'
|
||||
echo; echo "# versions in the root pom.xml of each release tag"
|
||||
printf '%-28s %-10s %-10s %-10s\n' property 2.0.0 2.0.3 2.1.0
|
||||
for p in spring-boot.version anthropic-sdk.version openai-sdk.version com.google.genai.version mcp.sdk.version awssdk.version kotlin.version java.version; do
|
||||
row=$(for v in 2.0.0 2.0.3 2.1.0; do sed -n "s:.*<$p>\([^<]*\)</$p>.*:\1:p" "target/bom/$v.root.xml" | head -1 | xargs printf '%-10s '; done)
|
||||
printf '%-28s %s\n' "$p" "$row"
|
||||
done
|
||||
} > output/15-bom-diff.txt
|
||||
cat output/15-bom-diff.txt
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
# Compile each file in broken/src against 2.0.3 and 2.1.0 and keep javac's own words.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
out=output/07-compile-breaks.txt
|
||||
echo "# javac on broken/src/*.java against two Spring AI versions" > "$out"
|
||||
for pair in 2.0.3:4.1.0 2.1.0:4.2.0; do
|
||||
v=${pair%:*}
|
||||
(cd probes && mvn -B -q dependency:build-classpath -Dspring-ai.version="$v" -Dboot.version="${pair#*:}" -Dmdep.outputFile="target/cp-$v.txt" >/dev/null 2>&1)
|
||||
cp=$(cat "probes/target/cp-$v.txt")
|
||||
echo >> "$out"; echo "== Spring AI $v" >> "$out"
|
||||
for f in broken/src/*.java; do
|
||||
tmp=$(mktemp -d)
|
||||
if msg=$(javac -J-Duser.language=en -proc:none -d "$tmp" -cp "$cp" "$f" 2>&1); then
|
||||
echo "$(basename "$f"): compiles" >> "$out"
|
||||
else
|
||||
echo "$(basename "$f"): FAILS" >> "$out"
|
||||
echo "$msg" | grep -v -e 'Picked up' | grep -e 'error:' -e 'symbol:' | sed -e "s#^$f# $(basename "$f")#" -e 's/^ *symbol:/ symbol:/' >> "$out"
|
||||
fi
|
||||
done
|
||||
done
|
||||
cat "$out"
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare Spring Boot configuration metadata between two directories of jars.
|
||||
usage: python3 -I scripts/config-diff.py target/jars/2.0.3 target/jars/2.1.0"""
|
||||
import collections
|
||||
import glob
|
||||
import json
|
||||
import sys
|
||||
import zipfile
|
||||
|
||||
|
||||
def load(directory):
|
||||
props = {}
|
||||
for jar in sorted(glob.glob(directory + "/*.jar")):
|
||||
with zipfile.ZipFile(jar) as z:
|
||||
if "META-INF/spring-configuration-metadata.json" in z.namelist():
|
||||
data = json.loads(z.read("META-INF/spring-configuration-metadata.json"))
|
||||
for p in data.get("properties", []):
|
||||
props.setdefault(p["name"], p)
|
||||
return props
|
||||
|
||||
|
||||
old, new = load(sys.argv[1]), load(sys.argv[2])
|
||||
removed = sorted(set(old) - set(new))
|
||||
added = sorted(set(new) - set(old))
|
||||
deprecated = [n for n in sorted(set(old) & set(new)) if new[n].get("deprecated") and not old[n].get("deprecated")]
|
||||
print(f"properties: old={len(old)} new={len(new)}")
|
||||
print(f"\nREMOVED: {len(removed)}")
|
||||
for n in removed:
|
||||
print(" " + n)
|
||||
print(f"\nNEWLY DEPRECATED: {len(deprecated)}")
|
||||
for n in deprecated:
|
||||
replacement = new[n].get("deprecation", {}).get("replacement")
|
||||
print(f" {n}" + (f" -> {replacement}" if replacement else ""))
|
||||
print(f"\nADDED: {len(added)}, by prefix")
|
||||
for prefix, count in sorted(collections.Counter(".".join(n.split(".")[:4]) for n in added).items()):
|
||||
print(f" {prefix} {count}")
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
# The three spring-ai-tool-search-tool-* entries are skipped: Maven Central answered 404 for their jars.
|
||||
# Download every non-starter jar listed in the Spring AI BOM of one version into target/jars/<version>.
|
||||
set -euo pipefail
|
||||
v=${1:?version}
|
||||
dir="$(cd "$(dirname "$0")/.." && pwd)/jars-cache/$v"
|
||||
base=https://repo1.maven.org/maven2/org/springframework/ai
|
||||
mkdir -p "$dir"
|
||||
curl -s -f --retry 5 "$base/spring-ai-bom/$v/spring-ai-bom-$v.pom" -o "$dir/../$v.bom"
|
||||
sed -n 's:.*<artifactId>\(spring-ai-[^<]*\)</artifactId>.*:\1:p' "$dir/../$v.bom" | sort -u \
|
||||
| grep -v -e '^spring-ai-bom$' -e '^spring-ai-starter' -e '^spring-ai-tool-search-tool-' > "$dir/../$v.artifacts"
|
||||
while read -r a; do
|
||||
[ -s "$dir/$a.jar" ] && continue
|
||||
code=$(curl -s -f --retry 8 --retry-delay 10 -o "$dir/$a.jar" -w '%{http_code}' "$base/$a/$v/$a-$v.jar" || true)
|
||||
case $code in
|
||||
200) ;;
|
||||
404) echo "in the BOM but not on Maven Central: $a $v" >&2 ;;
|
||||
*) echo "download failed (HTTP $code): $a $v; run again later" >&2; exit 1 ;;
|
||||
esac
|
||||
sleep 1
|
||||
done < "$dir/../$v.artifacts"
|
||||
echo "$v: $(ls "$dir" | wc -l) jars"
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
# Search a project for code and configuration that needs a decision on the way to Spring AI 2.1.
|
||||
# usage: scripts/grep-checklist.sh <project-dir>
|
||||
dir=${1:?project directory}
|
||||
cd "$dir" || exit 2
|
||||
|
||||
check() { # title, extended regex, file globs...
|
||||
local title=$1 regex=$2; shift 2
|
||||
local includes=(); for g in "$@"; do includes+=("--include=$g"); done
|
||||
local hits; hits=$(grep -rnE "${includes[@]}" --exclude-dir=target --exclude-dir=build -e "$regex" . | sed 's#^\./##' | sort)
|
||||
if [ -n "$hits" ]; then echo; echo "[ ] $title"; echo "$hits" | sed 's/^ */ /'; fi
|
||||
}
|
||||
|
||||
code=('*.java' '*.kt')
|
||||
conf=('*.properties' '*.yml' '*.yaml')
|
||||
build=('pom.xml' '*.gradle' '*.kts' '*.toml')
|
||||
|
||||
echo "# Spring AI 2.1 upgrade checklist: $(basename "$PWD")"
|
||||
check "ChatMemory API: deprecated, removed in 3.0.0 (move to sessions)" \
|
||||
'MessageChatMemoryAdvisor|MessageWindowChatMemory|ChatMemoryRepository|ChatMemory\b' "${code[@]}"
|
||||
check "Chat memory modules and properties" 'chat-memory-repository|chat-memory-redis' "${build[@]}"
|
||||
check "Chat memory properties (JDBC ones have spring.ai.session replacements)" 'spring\.ai\.chat\.memory' "${conf[@]}"
|
||||
check "Anthropic sampling options: discarded with a WARN on 2.1.0" '\.(temperature|topP|topK)\(' "${code[@]}"
|
||||
check "Anthropic sampling properties" 'spring\.ai\.anthropic\.chat\.(options\.)?(temperature|top-p|top-k)' "${conf[@]}"
|
||||
check "Token arithmetic on cache counters: prompt tokens include them since 2.0.3" 'getCache(Read|Write)InputTokens' "${code[@]}"
|
||||
check "x-api-key handling: Anthropic keys now travel as Authorization: Bearer" '[Xx]-[Aa][Pp][Ii]-[Kk]ey' "${code[@]}" "${conf[@]}" '*.conf'
|
||||
check "Reasoning read from metadata or extra generations" '"(isThought|thinking|signature|reasoningContent|thinking_content)"|THOUGHT_METADATA_KEY|THINKING_[A-Z_]*METADATA|getReasoningContent|DeepSeekAssistantMessage' "${code[@]}"
|
||||
check "Mutating message lists (now unmodifiable)" 'get(Media|ToolCalls)\(\)\.(add|addAll|remove|removeIf|clear)\(' "${code[@]}"
|
||||
check "Custom ToolCallingManager: delegate the ToolCallDecisions overload" 'implements +ToolCallingManager|: *ToolCallingManager' "${code[@]}"
|
||||
check "Bedrock requestParameters widened to Map<String, Object>" 'requestParameters' "${code[@]}"
|
||||
check "entity() with filtered or guarded replies: exception types changed" 'SafeGuardAdvisor' "${code[@]}"
|
||||
check "pgvector 'distance' metadata key" 'getMetadata\(\)\.get\("distance"\)|DocumentMetadata\.DISTANCE' "${code[@]}"
|
||||
check "MCP server customizers: deprecated in 2.1.0" 'Mcp(Async|Sync|StatelessAsync|StatelessSync)ServerCustomizer' "${code[@]}"
|
||||
check "TikaDocumentReader: 10,000,000 character limit since 2.0.3" 'new TikaDocumentReader' "${code[@]}"
|
||||
check "SemanticCacheAdvisor: a scope resolver is mandatory since 2.0.2" 'SemanticCacheAdvisor' "${code[@]}"
|
||||
check "Tool resolution fallback: off by default since 2.0.1" 'ToolCallbackResolver' "${code[@]}"
|
||||
check "Spring AI and Spring Boot versions" 'spring-ai(\.version|-bom)|spring-boot-starter-parent' "${build[@]}"
|
||||
echo
|
||||
echo "A hit is a place to read, not proof of a problem. No hit is not proof of safety."
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copy legacy-app, compile it as it is (2.0.0), run rewrite.yml, show the diff, compile again.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
work=$(mktemp -d)
|
||||
cp -r legacy-app "$work/app"; cp rewrite.yml "$work/app/"; cp -r legacy-app "$work/before"
|
||||
out=output/17-openrewrite.txt
|
||||
echo "# rewrite-maven-plugin 6.46.1 + rewrite-spring 6.37.1 with rewrite.yml on a copy of legacy-app" > "$out"
|
||||
(cd "$work/app" && mvn -B -q compile >/dev/null 2>&1) && echo "compile before (Boot 4.1.0, Spring AI 2.0.0): ok" >> "$out"
|
||||
for recipe in com.ankurm.SpringAi20To21Build com.ankurm.SpringAi20To21Code; do
|
||||
(cd "$work/app" && mvn -B org.openrewrite.maven:rewrite-maven-plugin:6.46.1:run \
|
||||
-Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:6.37.1 \
|
||||
-Drewrite.activeRecipes="$recipe" > "$work/rewrite.log" 2>&1) || { tail -40 "$work/rewrite.log"; exit 1; }
|
||||
done
|
||||
mv "$work/app/rewrite.yml" "$work/rewrite.used.yml"
|
||||
(cd "$work" && diff -ru -x target before app | sed -E 's/^(---|\+\+\+) ([^\t]+)\t.*/\1 \2/' | grep -v '^diff ') >> "$out" || true
|
||||
(cd "$work/app" && mvn -B clean compile > "$work/after.log" 2>&1) && echo "compile after (Boot 4.2.0, Spring AI 2.1.0): ok" >> "$out" \
|
||||
|| { echo "compile after: FAILED" >> "$out"; grep ERROR "$work/after.log" | head >> "$out"; }
|
||||
# The same two recipes in ONE Maven invocation: types are still those of 2.0.0.
|
||||
cp -r legacy-app "$work/one"; cp rewrite.yml "$work/one/"
|
||||
(cd "$work/one" && mvn -B org.openrewrite.maven:rewrite-maven-plugin:6.46.1:run \
|
||||
-Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:6.37.1 \
|
||||
-Drewrite.activeRecipes=com.ankurm.SpringAi20To21Build,com.ankurm.SpringAi20To21Code > "$work/one.log" 2>&1)
|
||||
{ echo; echo "both recipes in one invocation, sampling calls left in SupportBot.java:"
|
||||
grep -nE '\.(temperature|topK|topP)\(' "$work/one/src/main/java/com/ankurm/legacy/SupportBot.java" || echo " none"; } >> "$out"
|
||||
cat "$out"
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regenerates every file in output/. Needs JDK 25, Maven, Docker (for 11-upsert) and network
|
||||
# access to Maven Central and GitHub. No model provider is called and no API key is needed.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
mkdir -p target
|
||||
echo "== probes: one source tree against four Spring AI versions"
|
||||
for pair in 2.0.0:4.1.0 2.0.2:4.1.0 2.0.3:4.1.0 2.1.0:4.2.0; do
|
||||
v=${pair%:*}
|
||||
(cd probes && mvn -B clean test -Dspring-ai.version="$v" -Dboot.version="${pair#*:}" > "../target/probe-$v.log")
|
||||
done
|
||||
{
|
||||
echo "# javac -Xlint:deprecation,removal on probes/.../LegacyAssistant.java (from the Maven build log)"
|
||||
for v in 2.0.3 2.1.0; do echo "Spring AI $v: $(grep -c 'WARNING.*LegacyAssistant' "target/probe-$v.log" || true) warnings"; done
|
||||
grep 'WARNING.*LegacyAssistant' target/probe-2.1.0.log \
|
||||
| sed -E 's#.*LegacyAssistant.java:#LegacyAssistant.java:#; s/org\.springframework\.ai\.//g; s/@org\.jspecify\.annotations\.Nullable java\.lang\.//'
|
||||
} > output/06-legacy-warnings.txt
|
||||
echo "== compile breaks"; scripts/compile-breaks.sh > /dev/null
|
||||
echo "== 2.1.0 module"; mvn -B clean test > target-main.log; mkdir -p target && mv target-main.log target/main.log
|
||||
echo "== API, config, BOM"; scripts/api-diff.sh > /dev/null; scripts/bom-diff.sh > /dev/null
|
||||
echo "== checklist"; scripts/grep-checklist.sh legacy-app > output/16-grep-checklist.txt
|
||||
echo "== OpenRewrite"; scripts/openrewrite.sh > /dev/null
|
||||
echo done
|
||||
Reference in New Issue
Block a user