Support for Gradle dependencyResolutionManagement RepositoriesMode.PREFER_SETTINGS #605
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes #594 (comment)
Changes influence only builds when main Gradle template patching is enabled.
Changes:
settingsTemplate.gradle
/resolve/gradlesettingstemplate
report URL to the analytics. (Not sure if it is needed)The logic of repositories injection depends on the project state:
mainTemplate.gradle
andsettingsTemplate.gradle
are enabled and mainTemplate patching and settingsTemplate patching in Android Resolver settings are enabled:settingsTemplate.gradle
containsdependencyResolutionManagement
block withRepositoriesMode.PREFER_SETTINGS
orRepositoriesMode.FAIL_ON_PROJECT_REPOS
. If the match is successful it would mean that Gradle is configured to read repositories fromsettingsTemplate.gradle
and will not read repositories specified inmainTemplate.gradle
.settingsTemplate.gradle
beforedependencyResolutionManagement
line. Injected repositories are in separatedependencyResolutionManagement
block and look like this:mainTemplate.gradle
mainTemplate.gradle
andsettingsTemplate.gradle
are enabled and mainTemplate patching is enabled but settingsTemplate patching in Android Resolver settings is disabled, Android Resolver will not patchsettingsTemplate.gradle
this will lead to the build fail and the user will need to manage repositories manually.mainTemplate.gradle
is enabled and mainTemplate patching and settingsTemplate patching in Android Resolver settings are enabled butsettingsTemplate.gradle
is disabled:settingsTemplate.gradle
inPlaybackEngines/AndroidPlayer/Tools/GradleTemplates
containsdependencyResolutionManagement
block. Effectively this will match any Unity version equal to or above the 2022.2 version becausedependencyResolutionManagement
was introduced in the 2022.2 version.2.1. If the previous check didn't match then Android Resolver will work as in the previous versions.
2.2. If the previous check is successful then Android Resolver will enable
settingsTemplate.gradle
automatically (by copying the default template). Decided to do it in such a way because Unity >=2022.2 and <2022.2.10 uses a settings template for repositories but don't have an option in "Project Settings" to enable a custom settings template. This option appeared only in 2022.2.10.