Skip to content

Commit 3e12002

Browse files
Resolve mvn via M2_HOME/MAVEN_HOME for CI agents
TeamCity agents may not have mvn on PATH. Check M2_HOME and MAVEN_HOME before falling back to PATH lookup. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5e830a1 commit 3e12002

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

generate-client.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ if [ ! -f "$GENERATOR_JAR" ]; then
104104
fi
105105
openapi-generator-cli() { java -jar "$GENERATOR_JAR" "$@"; }
106106

107+
# Resolve mvn: prefer M2_HOME/MAVEN_HOME, fall back to PATH
108+
if [ -n "${M2_HOME:-}" ] && [ -x "$M2_HOME/bin/mvn" ]; then
109+
MVN="$M2_HOME/bin/mvn"
110+
elif [ -n "${MAVEN_HOME:-}" ] && [ -x "$MAVEN_HOME/bin/mvn" ]; then
111+
MVN="$MAVEN_HOME/bin/mvn"
112+
elif command -v mvn >/dev/null 2>&1; then
113+
MVN="mvn"
114+
else
115+
echo "Error: mvn not found. Set M2_HOME or MAVEN_HOME, or add mvn to PATH."
116+
exit 1
117+
fi
118+
107119
generate() {
108120
local edition="$1"
109121
local spec_file="$SCRIPT_DIR/$edition/spec/openapi.json"
@@ -228,9 +240,9 @@ fi
228240
if [ "$DRY_RUN" = false ]; then
229241
# Apply license headers and stage changes
230242
if [ "$VERBOSE" = true ]; then
231-
mvn -f "$SCRIPT_DIR/pom.xml" license:format
243+
"$MVN" -f "$SCRIPT_DIR/pom.xml" license:format
232244
else
233-
mvn -f "$SCRIPT_DIR/pom.xml" license:format -q
245+
"$MVN" -f "$SCRIPT_DIR/pom.xml" license:format -q
234246
fi
235247
git -C "$SCRIPT_DIR" add .
236248
fi

0 commit comments

Comments
 (0)