Skip to content

Commit d4f2161

Browse files
authored
ADFA-1140 Move CoGo-specific Gradle configuration from build files to our Gradle plugins (#325)
Move maven local repo configuration from template projects setting.gradle(.kts) to cogo-plugin. Restore repository values required for builds in online mode and external IDE (i.e. Android Studio)
1 parent b30fd44 commit d4f2161

3 files changed

Lines changed: 56 additions & 14 deletions

File tree

‎composite-builds/build-deps-common/constants/src/main/java/org/adfa/constants/constants.kt‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ const val ARM_KEY = "armeabi"
5656

5757
//Local maven repo
5858
const val LOCAL_MAVEN_REPO_ARCHIVE_ZIP_NAME = "localMvnRepository.zip"
59-
val LOCAL_MAVEN_CACHES_DEST = HOME_PATH + File.separator + "maven"
59+
const val LOCAL_MAVEN_CACHES_DEST = "$HOME_PATH/maven"
6060
const val LOCAL_MAVEN_REPO_FOLDER_DEST = "localMvnRepository"
6161

62+
@Suppress("SdCardPath")
63+
const val MAVEN_LOCAL_REPOSITORY = "/data/data/com.itsaky.androidide/files/$LOCAL_MAVEN_CACHES_DEST/$LOCAL_MAVEN_REPO_FOLDER_DEST"
64+
6265
// Tooltips
6366
const val CONTENT_KEY = "CONTENT_KEY"
6467
const val CONTENT_TITLE_KEY = "CONTENT_TITLE_KEY"

‎gradle-plugin/src/main/java/com/itsaky/androidide/gradle/AndroidIDEInitScriptPlugin.kt‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.itsaky.androidide.buildinfo.BuildInfo
2121
import com.itsaky.androidide.tooling.api.LogSenderConfig._PROPERTY_IS_TEST_ENV
2222
import com.itsaky.androidide.tooling.api.LogSenderConfig._PROPERTY_MAVEN_LOCAL_REPOSITORY
2323
import org.adfa.constants.ANDROIDIDE_HOME
24+
import org.adfa.constants.MAVEN_LOCAL_REPOSITORY
2425
import org.gradle.StartParameter
2526
import org.gradle.api.Plugin
2627
import org.gradle.api.artifacts.ExternalModuleDependency
@@ -60,7 +61,9 @@ class AndroidIDEInitScriptPlugin : Plugin<Gradle> {
6061
override fun apply(target: Gradle) {
6162
removeDaemonLogs(target)
6263

63-
// NOTE disable access to non-local repos
64+
target.settingsEvaluated { settings ->
65+
settings.addDependencyRepositories()
66+
}
6467

6568
target.rootProject { rootProject ->
6669
rootProject.buildscript.apply {
@@ -115,7 +118,39 @@ class AndroidIDEInitScriptPlugin : Plugin<Gradle> {
115118

116119
private fun Settings.addDependencyRepositories() {
117120
val (isTestEnv, mavenLocalRepos) = getTestEnvProps(startParameter)
118-
addDependencyRepositories(isTestEnv, mavenLocalRepos)
121+
if (isTestEnv) {
122+
addDependencyRepositories(isTestEnv, mavenLocalRepos)
123+
} else {
124+
addDependencyRepositories(MAVEN_LOCAL_REPOSITORY)
125+
}
126+
}
127+
128+
@Suppress("UnstableApiUsage")
129+
private fun Settings.addDependencyRepositories(
130+
mavenLocalRepo: String
131+
) {
132+
dependencyResolutionManagement.run {
133+
repositories.configureRepositories(mavenLocalRepo)
134+
}
135+
136+
pluginManagement.apply {
137+
repositories.configureRepositories(mavenLocalRepo)
138+
}
139+
}
140+
141+
private fun RepositoryHandler.configureRepositories(
142+
mavenLocalRepo: String
143+
) {
144+
145+
val repo = File(mavenLocalRepo)
146+
if (!repo.exists() || !repo.isDirectory) {
147+
throw FileNotFoundException("Maven local repository '$mavenLocalRepo' not found")
148+
}
149+
150+
maven { repository ->
151+
repository.url = repo.toURI()
152+
}
153+
119154
}
120155

121156
@Suppress("UnstableApiUsage")

‎templates-api/src/main/java/com/itsaky/androidide/templates/base/root/settings.kt‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package com.itsaky.androidide.templates.base.root
1919

20-
import org.adfa.constants.LOCAL_MAVEN_CACHES_DEST
21-
import org.adfa.constants.LOCAL_MAVEN_REPO_FOLDER_DEST
2220
import com.itsaky.androidide.templates.base.ProjectTemplateBuilder
2321

2422
/**
@@ -31,14 +29,17 @@ internal fun ProjectTemplateBuilder.settingsGradleSrcStr(): String {
3129
return """
3230
pluginManagement {
3331
repositories {
34-
maven(uri("/data/data/com.itsaky.androidide/files/$LOCAL_MAVEN_CACHES_DEST/$LOCAL_MAVEN_REPO_FOLDER_DEST"))
32+
gradlePluginPortal()
33+
google()
34+
mavenCentral()
3535
}
3636
}
3737
3838
dependencyResolutionManagement {
3939
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
4040
repositories {
41-
maven(uri("/data/data/com.itsaky.androidide/files/$LOCAL_MAVEN_CACHES_DEST/$LOCAL_MAVEN_REPO_FOLDER_DEST"))
41+
google()
42+
mavenCentral()
4243
}
4344
}
4445
@@ -51,16 +52,19 @@ ${modules.joinToString(separator = ", ") { "include(\"${it.name}\")" }}
5152
internal fun ProjectTemplateBuilder.settingsGroovyGradleSrcStr(): String {
5253
return """
5354
pluginManagement {
54-
repositories {
55-
maven { url = uri("/data/data/com.itsaky.androidide/files/$LOCAL_MAVEN_CACHES_DEST/$LOCAL_MAVEN_REPO_FOLDER_DEST") }
56-
}
55+
repositories {
56+
gradlePluginPortal()
57+
google()
58+
mavenCentral()
59+
}
5760
}
5861
5962
dependencyResolutionManagement {
60-
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
61-
repositories {
62-
maven { url = uri("/data/data/com.itsaky.androidide/files/$LOCAL_MAVEN_CACHES_DEST/$LOCAL_MAVEN_REPO_FOLDER_DEST") }
63-
}
63+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
64+
repositories {
65+
google()
66+
mavenCentral()
67+
}
6468
}
6569
6670
rootProject.name = "${data.name}"

0 commit comments

Comments
 (0)