forked from DicioTeam/dicio-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.gradle.kts
More file actions
118 lines (106 loc) · 3.78 KB
/
settings.gradle.kts
File metadata and controls
118 lines (106 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import me.champeau.gradle.igp.gitRepositories
import org.eclipse.jgit.api.Git
import java.io.FileInputStream
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.StandardCopyOption
import java.util.Properties
rootProject.name = "Dicio"
include(":app")
include(":skill")
// we use includeBuild here since the plugin is a compile-time dependency
includeBuild("sentences-compiler-plugin")
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
plugins {
// not using version catalog because it is not available in settings.gradle.kts
id("me.champeau.includegit") version "0.1.6"
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
// All of the code below handles depending on libraries from git repos, in particular dicio-numbers,
// dicio-skill and dicio-sentences-compiler. The git commits to checkout can be updated here.
// If you want to use a local copy of the projects (provided that you have cloned them in
// `../dicio-*`), you can add `useLocalDicioLibraries=true` in `local.properties`.
data class IncludeGitRepo(
val name: String,
val uri: String,
val projectPath: String,
val commit: String,
)
val includeGitRepos = listOf(
IncludeGitRepo(
name = "dicio-numbers",
uri = "https://github.com/Stypox/dicio-numbers",
projectPath = ":numbers",
commit = "66fd44b79585f952b76d16e5578d4d6aa5bc030c",
),
IncludeGitRepo(
name = "dicio-sentences-compiler",
uri = "https://github.com/Stypox/dicio-sentences-compiler",
projectPath = ":sentences_compiler",
commit = "7d83fe5a3d6dff2fc81b5c40783a1d82ada293d3",
),
)
val localProperties = Properties().apply {
try {
load(FileInputStream(File(rootDir, "local.properties")))
} catch (e: Throwable) {
println("Warning: can't read local.properties: $e")
}
}
if (localProperties.getOrDefault("useLocalDicioLibraries", "") == "true") {
for (repo in includeGitRepos) {
includeBuild("../${repo.name}") {
dependencySubstitution {
substitute(module("git.included.build:${repo.name}"))
.using(project(repo.projectPath))
}
}
}
} else {
// if the repo has already been cloned, the gitRepositories plugin is buggy and doesn't
// fetch the remote repo before trying to checkout the commit (in case the commit has changed),
// and doesn't clone the repo again if the remote changed, so we need to do it manually
for (repo in includeGitRepos) {
val file = File("$rootDir/checkouts/${repo.name}")
if (file.isDirectory) {
val git = Git.open(file)
val sameRemote = git.remoteList().call()
.any { rem -> rem.urIs.any { uri -> uri.toString() == repo.uri } }
if (sameRemote) {
// the commit may have changed, fetch again
git.fetch().call()
} else {
// the remote changed, delete the repository and start from scratch
println("Git: remote for ${repo.name} changed, deleting the current folder")
file.deleteRecursively()
}
}
}
gitRepositories {
for (repo in includeGitRepos) {
include(repo.name) {
uri.set(repo.uri)
commit.set(repo.commit)
autoInclude.set(false)
includeBuild("") {
dependencySubstitution {
substitute(module("git.included.build:${repo.name}"))
.using(project(repo.projectPath))
}
}
}
}
}
}