Skip to content

Commit 6db52e7

Browse files
committed
Another attempt
1 parent 7c34987 commit 6db52e7

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

scripts/build-android-app.sh

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ ba_log "Generating Codename One application skeleton via codenameone-maven-plugi
116116

117117
APP_DIR="$WORK_DIR/$ARTIFACT_ID"
118118

119-
# --- Normalize Codename One versions (safe for Maven parent resolution) ---
119+
# --- Robust CN1 version normalization & plugin version injection ---
120120

121121
ROOT_POM="$APP_DIR/pom.xml"
122122

123-
# 0) Ensure property exists (you can keep this for deps/plugins)
123+
# 0) Ensure property exists for deps/plugins (not used for parent)
124124
ensure_property() {
125125
local pom="$1" name="$2" value="$3"
126126
if ! grep -q "<properties>" "$pom"; then
@@ -140,26 +140,60 @@ ensure_property() {
140140
}
141141
ensure_property "$ROOT_POM" "codenameone.version" "$CN1_VERSION"
142142

143-
# 1) Parent: set literal version (Maven DOES NOT allow a property here)
143+
# 1) Parent must be literal version (Maven cannot resolve a property here)
144144
while IFS= read -r -d '' P; do
145145
perl -0777 -pe 's!(<parent>\s*<groupId>com\.codenameone</groupId>\s*<artifactId>codenameone-maven-parent</artifactId>\s*<version>)[^<]+(</version>)!$1'"$CN1_VERSION"'$2!s' -i "$P"
146146
done < <(find "$APP_DIR" -type f -name pom.xml -print0)
147147

148-
# 2) com.codenameone deps/plugins -> use the property (optional but tidy)
148+
# 2) CN1 deps/plugins -> property
149149
while IFS= read -r -d '' P; do
150150
perl -0777 -pe 's!(<dependency>\s*<groupId>com\.codenameone[^<]*</groupId>\s*<artifactId>[^<]+</artifactId>\s*<version>)[^<]+(</version>)!${1}${codenameone.version}${2}!sg' -i "$P"
151151
perl -0777 -pe 's!(<plugin>\s*<groupId>com\.codenameone[^<]*</groupId>\s*<artifactId>[^<]+</artifactId>\s*<version>)[^<]+(</version>)!${1}${codenameone.version}${2}!sg' -i "$P"
152152
done < <(find "$APP_DIR" -type f -name pom.xml -print0)
153153

154-
# 3) Build with the property set (covers any missed spots)
154+
# 3) Inject versions for plugins that have none (both build/plugins and pluginManagement)
155+
# Map of common Maven plugin versions (adjust if you need different pins)
156+
declare -A PLUG_VERSIONS=(
157+
[org.apache.maven.plugins:maven-compiler-plugin]=3.11.0
158+
[org.apache.maven.plugins:maven-surefire-plugin]=3.2.5
159+
[org.apache.maven.plugins:maven-failsafe-plugin]=3.2.5
160+
[org.apache.maven.plugins:maven-jar-plugin]=3.3.0
161+
[org.apache.maven.plugins:maven-resources-plugin]=3.3.1
162+
[org.apache.maven.plugins:maven-install-plugin]=3.1.2
163+
[org.apache.maven.plugins:maven-deploy-plugin]=3.1.2
164+
[org.apache.maven.plugins:maven-clean-plugin]=3.3.2
165+
[org.apache.maven.plugins:maven-site-plugin]=4.0.0-M15
166+
[org.apache.maven.plugins:maven-assembly-plugin]=3.6.0
167+
# If the generated app declares Codename One plugin without version (shouldn’t after step 2), this covers it:
168+
[com.codenameone:codenameone-maven-plugin]="${CN1_VERSION}"
169+
)
170+
171+
inject_plugin_versions_file() {
172+
local pom="$1"
173+
# For each known plugin, if present without <version>, insert one
174+
for ga in "${!PLUG_VERSIONS[@]}"; do
175+
local g="${ga%%:*}"; local a="${ga##*:}"; local v="${PLUG_VERSIONS[$ga]}"
176+
# build/plugins
177+
perl -0777 -pe 's!(<plugin>\s*<groupId>'"$g"'</groupId>\s*<artifactId>'"$a"'</artifactId>\s*)(?!.*?<version>.*?</version>)(?=.*?</plugin>)!\1<version>'"$v"'</version>\n!sg' -i "$pom"
178+
# pluginManagement/plugins
179+
perl -0777 -pe 's!(<plugin>\s*<groupId>'"$g"'</groupId>\s*<artifactId>'"$a"'</artifactId>\s*)(?!.*?<version>.*?</version>)(?=.*?</plugin>)!\1<version>'"$v"'</version>\n!sg' -i "$pom"
180+
done
181+
}
182+
183+
while IFS= read -r -d '' P; do
184+
inject_plugin_versions_file "$P"
185+
done < <(find "$APP_DIR" -type f -name pom.xml -print0)
186+
187+
# 4) Build with the property set (covers any lingering references)
155188
EXTRA_MVN_ARGS+=("-Dcodenameone.version=${CN1_VERSION}")
156189

157-
# Show parent block without failing the build
158-
grep -n -A3 -B3 '<parent>' "$APP_DIR/pom.xml" || true
190+
# 5) Non-fatal debug (won’t fail the build)
191+
grep -n -A3 -B3 '<parent>' "$ROOT_POM" || true
192+
grep -n 'artifactId>maven-compiler-plugin' -n -A2 -B2 "$ROOT_POM" || true
193+
194+
nl -ba "$ROOT_POM" | sed -n '1,140p' || true
195+
159196

160-
# Optional: dump effective POM to inspect pluginManagement
161-
"${MAVEN_HOME}/bin/mvn" -q -f "$APP_DIR/pom.xml" help:effective-pom -Doutput="$APP_DIR/effective-pom.xml" || true
162-
tail -n +1 "$APP_DIR/effective-pom.xml" | sed -n '1,200p' >/dev/null || true
163197

164198
[ -d "$APP_DIR" ] || { ba_log "Failed to create Codename One application project" >&2; exit 1; }
165199
[ -f "$APP_DIR/build.sh" ] && chmod +x "$APP_DIR/build.sh"

0 commit comments

Comments
 (0)