@@ -188,24 +188,60 @@ EOF
188188 else
189189 # Check and add missing repositories in pluginManagement
190190 if ! grep -A 10 " pluginManagement" " $SETTINGS_GRADLE " | grep -q " gradlePluginPortal()" ; then
191- sed -i ' /pluginManagement {/,/}/ { /repositories {/a\
192- gradlePluginPortal()
193- }' " $SETTINGS_GRADLE "
191+ # Using awk for portability across macOS and Linux
192+ awk '
193+ /pluginManagement \{/,/\}/ {
194+ if ($0 ~ /repositories \{/ && !found) {
195+ print $0
196+ print " gradlePluginPortal()"
197+ found=1
198+ next
199+ }
200+ }
201+ { print }
202+ ' " $SETTINGS_GRADLE " > " $SETTINGS_GRADLE .tmp" && mv " $SETTINGS_GRADLE .tmp" " $SETTINGS_GRADLE "
194203 fi
195204 if ! grep -A 10 " pluginManagement" " $SETTINGS_GRADLE " | grep -q " google()" ; then
196- sed -i ' /pluginManagement {/,/}/ { /repositories {/a\
197- google()
198- }' " $SETTINGS_GRADLE "
205+ # Using awk for portability across macOS and Linux
206+ awk '
207+ /pluginManagement \{/,/\}/ {
208+ if ($0 ~ /repositories \{/ && !found) {
209+ print $0
210+ print " google()"
211+ found=1
212+ next
213+ }
214+ }
215+ { print }
216+ ' " $SETTINGS_GRADLE " > " $SETTINGS_GRADLE .tmp" && mv " $SETTINGS_GRADLE .tmp" " $SETTINGS_GRADLE "
199217 fi
200218 if ! grep -A 10 " pluginManagement" " $SETTINGS_GRADLE " | grep -q " mavenCentral()" ; then
201- sed -i ' /pluginManagement {/,/}/ { /repositories {/a\
202- mavenCentral()
203- }' " $SETTINGS_GRADLE "
219+ # Using awk for portability across macOS and Linux
220+ awk '
221+ /pluginManagement \{/,/\}/ {
222+ if ($0 ~ /repositories \{/ && !found) {
223+ print $0
224+ print " mavenCentral()"
225+ found=1
226+ next
227+ }
228+ }
229+ { print }
230+ ' " $SETTINGS_GRADLE " > " $SETTINGS_GRADLE .tmp" && mv " $SETTINGS_GRADLE .tmp" " $SETTINGS_GRADLE "
204231 fi
205232 if ! grep -A 10 " pluginManagement" " $SETTINGS_GRADLE " | grep -q " jitpack.io" ; then
206- sed -i ' /pluginManagement {/,/}/ { /repositories {/a\
207- maven { url = uri("https://jitpack.io") }
208- }' " $SETTINGS_GRADLE "
233+ # Using awk for portability across macOS and Linux
234+ awk '
235+ /pluginManagement \{/,/\}/ {
236+ if ($0 ~ /repositories \{/ && !found) {
237+ print $0
238+ print " maven { url = uri(\"https://jitpack.io\") }"
239+ found=1
240+ next
241+ }
242+ }
243+ { print }
244+ ' " $SETTINGS_GRADLE " > " $SETTINGS_GRADLE .tmp" && mv " $SETTINGS_GRADLE .tmp" " $SETTINGS_GRADLE "
209245 fi
210246 fi
211247fi
0 commit comments