How to prevent unity from overwriting gradle files when exporting again?

When exporting android project with early version, ie. Unity 2020, removing the first comment line will prevent overwriting when exporting again. Like this:

// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
apply plugin: 'com.android.library'
....

But when I upgrade to Unity 2021.3 (LTS),this line is gone and overwriting always happens .
Now I have to enable custom-gradle in Unity project and export again and again whenever I changed the gradle. It’s a inefficient way.
Is there any option to prevent Uity2021 from overwriting gradle files exist in android project ?

In 2021.2, Android build pipeline became incremental, thus this is expected.

Your options are either to use templates or to use https://docs.unity3d.com/ScriptReference/Android.IPostGenerateGradleAndroidProject.html and keep overwriting gradle file.

In future Unity versions (hopefully 2023.1) we’ll provide an API for manipulating gradle files in a more user friendly way.