@@ -151,8 +151,8 @@ while IFS= read -r -d '' P; do
151151 perl -0777 -pe ' s!(<plugin>\s*<groupId>com\.codenameone[^<]*</groupId>\s*<artifactId>[^<]+</artifactId>\s*<version>)[^<]+(</version>)!${1}${codenameone.version}${2}!sg' -i " $P "
152152done < <( find " $APP_DIR " -type f -name pom.xml -print0)
153153
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)
154+ # 3) Inject versions for plugins that have none (or update existing ones) — no lookaheads
155+
156156declare -A PLUG_VERSIONS=(
157157 [org.apache.maven.plugins:maven-compiler-plugin]=3.11.0
158158 [org.apache.maven.plugins:maven-surefire-plugin]=3.2.5
@@ -164,27 +164,39 @@ declare -A PLUG_VERSIONS=(
164164 [org.apache.maven.plugins:maven-clean-plugin]=3.3.2
165165 [org.apache.maven.plugins:maven-site-plugin]=4.0.0-M15
166166 [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} "
167+ [com.codenameone:codenameone-maven-plugin]=" $CN1_VERSION "
169168)
170169
171170inject_plugin_versions_file () {
172171 local pom=" $1 "
173- # For each known plugin, if present without <version>, insert one
174172 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 "
173+ local g=" ${ga%%:* } " a=" ${ga##*: } " v=" ${PLUG_VERSIONS[$ga]} "
174+
175+ # Pass 1: update existing <version>...</version> for this plugin
176+ perl -0777 -i -pe \
177+ " s!(<plugin>\\ s*<groupId>\\ Q$g \\ E</groupId>\\ s*<artifactId>\\ Q$a \\ E</artifactId>\\ s*<version>)[^<]+(</version>)!\$ 1$v \$ 2!sg" \
178+ " $pom "
179+
180+ # Pass 2: if there is NO version yet, insert it right after </artifactId>
181+ perl -0777 -i -pe \
182+ " s!(<plugin>\\ s*<groupId>\\ Q$g \\ E</groupId>\\ s*<artifactId>\\ Q$a \\ E</artifactId>\\ s*)(?!.*?<version>)(?:(?:(?!</plugin>).)*</plugin>)!${1} <version>$v </version>\n!sg" \
183+ " $pom " 2> /dev/null || true
184+
185+ # The line above still uses a tiny lookahead; if you want *zero* lookaheads at all,
186+ # use this alternative pure two-step approach (slower, but bulletproof):
187+ # if ! grep -zq "<groupId>$g</groupId>.*<artifactId>$a</artifactId>.*<version>" "$pom"; then
188+ # perl -0777 -i -pe \
189+ # "s!(<plugin>\\s*<groupId>\\Q$g\\E</groupId>\\s*<artifactId>\\Q$a\\E</artifactId>\\s*)!\\1<version>$v</version>\n!s" \
190+ # "$pom"
191+ # fi
180192 done
181193}
182194
183195while IFS= read -r -d ' ' P; do
184196 inject_plugin_versions_file " $P "
185197done < <( find " $APP_DIR " -type f -name pom.xml -print0)
186198
187- # 4) Build with the property set (covers any lingering references)
199+ # 4) Keep this so any remaining CN1 refs resolve to your local snapshot
188200EXTRA_MVN_ARGS+=(" -Dcodenameone.version=${CN1_VERSION} " )
189201
190202# 5) Non-fatal debug (won’t fail the build)
0 commit comments