Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit a9195f0

Browse files
committed
build(build-logic): modularize :build-logic composite build
1 parent 8ae87d7 commit a9195f0

File tree

86 files changed

+364
-135
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+364
-135
lines changed

.idea/compiler.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actions/build.gradle.kts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* This file is part of AndroidIDE.
3+
*
4+
* AndroidIDE is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* AndroidIDE is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
import com.itsaky.androidide.build.config.BuildConfig
19+
120
plugins{
221
id("com.android.library")
322
id("kotlin-android")

annotation-processors-ksp/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2-
31
/*
42
* This file is part of AndroidIDE.
53
*
@@ -17,6 +15,9 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
1715
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
1816
*/
1917

18+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
19+
import com.itsaky.androidide.build.config.BuildConfig
20+
2021
plugins {
2122
kotlin("jvm")
2223
}

annotation-processors/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2-
31
/*
42
* This file is part of AndroidIDE.
53
*
@@ -17,6 +15,9 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
1715
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
1816
*/
1917

18+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
19+
import com.itsaky.androidide.build.config.BuildConfig
20+
2021
plugins {
2122
kotlin("jvm")
2223
}

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@file:Suppress("UnstableApiUsage")
22

33
import com.itsaky.androidide.plugins.AndroidIDEAssetsPlugin
4+
import com.itsaky.androidide.build.config.BuildConfig
45

56
plugins {
67
id("com.android.application")

build-info/build.gradle.kts

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.jetbrains.kotlin.incremental.createDirectory
2-
31
/*
42
* This file is part of AndroidIDE.
53
*
@@ -17,14 +15,28 @@ import org.jetbrains.kotlin.incremental.createDirectory
1715
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
1816
*/
1917

18+
import com.itsaky.androidide.build.config.AGP_VERSION_MINIMUM
19+
import com.itsaky.androidide.build.config.BuildConfig
20+
import com.itsaky.androidide.build.config.CI
21+
import com.itsaky.androidide.build.config.FDroidConfig
22+
import com.itsaky.androidide.build.config.ProjectConfig
23+
import com.itsaky.androidide.build.config.VersionUtils
24+
import com.itsaky.androidide.build.config.downloadVersion
25+
import com.itsaky.androidide.build.config.publishingVersion
26+
import com.itsaky.androidide.build.config.replaceContents
27+
import com.itsaky.androidide.build.config.simpleVersionName
28+
import org.jetbrains.kotlin.incremental.createDirectory
29+
2030
plugins {
31+
//noinspection JavaPluginLanguageLevel
2132
id("java-library")
2233
id("com.vanniktech.maven.publish.base")
2334
}
2435

2536
description = "Information about the AndroidIDE build"
2637

27-
val buildInfoGenDir: Provider<Directory> = project.layout.buildDirectory.dir("generated/buildInfo").also { it.get().asFile.createDirectory() }
38+
val buildInfoGenDir: Provider<Directory> = project.layout.buildDirectory.dir("generated/buildInfo")
39+
.also { it.get().asFile.createDirectory() }
2840

2941
sourceSets { getByName("main").java.srcDir(buildInfoGenDir) }
3042

@@ -38,34 +50,34 @@ tasks.create("generateBuildInfo") {
3850
dest = buildInfo.asFile,
3951
comment = "//",
4052
candidates =
41-
arrayOf(
42-
"PACKAGE_NAME" to BuildConfig.packageName,
43-
"MVN_GROUP_ID" to BuildConfig.packageName,
53+
arrayOf(
54+
"PACKAGE_NAME" to BuildConfig.packageName,
55+
"MVN_GROUP_ID" to BuildConfig.packageName,
4456

45-
"VERSION_NAME" to rootProject.version.toString(),
46-
"VERSION_NAME_SIMPLE" to rootProject.simpleVersionName,
47-
"VERSION_NAME_PUBLISHING" to rootProject.publishingVersion,
48-
"VERSION_NAME_DOWNLOAD" to rootProject.downloadVersion,
57+
"VERSION_NAME" to rootProject.version.toString(),
58+
"VERSION_NAME_SIMPLE" to rootProject.simpleVersionName,
59+
"VERSION_NAME_PUBLISHING" to rootProject.publishingVersion,
60+
"VERSION_NAME_DOWNLOAD" to rootProject.downloadVersion,
4961

50-
"FDROID_BUILD" to FDroidConfig.isFDroidBuild.toString(),
51-
"FDROID_BUILD_VERSION_NAME" to (FDroidConfig.fDroidVersionName ?: "null"),
52-
"FDROID_BUILD_VERSION_CODE" to (FDroidConfig.fDroidVersionCode ?: -1).toString(),
62+
"FDROID_BUILD" to FDroidConfig.isFDroidBuild.toString(),
63+
"FDROID_BUILD_VERSION_NAME" to (FDroidConfig.fDroidVersionName ?: "null"),
64+
"FDROID_BUILD_VERSION_CODE" to (FDroidConfig.fDroidVersionCode ?: -1).toString(),
5365

54-
"CI_BUILD" to CI.isCiBuild.toString(),
55-
"CI_GIT_BRANCH" to CI.branchName,
56-
"CI_COMMIT_HASH" to CI.commitHash,
66+
"CI_BUILD" to CI.isCiBuild.toString(),
67+
"CI_GIT_BRANCH" to CI.branchName,
68+
"CI_COMMIT_HASH" to CI.commitHash,
5769

58-
"REPO_HOST" to ProjectConfig.REPO_HOST,
59-
"REPO_OWNER" to ProjectConfig.REPO_OWNER,
60-
"REPO_NAME" to ProjectConfig.REPO_NAME,
61-
"PROJECT_SITE" to ProjectConfig.PROJECT_SITE,
70+
"REPO_HOST" to ProjectConfig.REPO_HOST,
71+
"REPO_OWNER" to ProjectConfig.REPO_OWNER,
72+
"REPO_NAME" to ProjectConfig.REPO_NAME,
73+
"PROJECT_SITE" to ProjectConfig.PROJECT_SITE,
6274

63-
"AGP_VERSION_MININUM" to AGP_VERSION_MINIMUM,
64-
"AGP_VERSION_LATEST" to libs.versions.agp.tooling.get(),
75+
"AGP_VERSION_MININUM" to AGP_VERSION_MINIMUM,
76+
"AGP_VERSION_LATEST" to libs.versions.agp.tooling.get(),
6577

66-
"SNAPSHOTS_REPOSITORY" to VersionUtils.SONATYPE_SNAPSHOTS_REPO,
67-
"PUBLIC_REPOSITORY" to VersionUtils.SONATYPE_PUBLIC_REPO,
68-
)
78+
"SNAPSHOTS_REPOSITORY" to VersionUtils.SONATYPE_SNAPSHOTS_REPO,
79+
"PUBLIC_REPOSITORY" to VersionUtils.SONATYPE_PUBLIC_REPO,
80+
)
6981
)
7082
}
7183
}

build-logic/build.gradle.kts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* This file is part of AndroidIDE.
3+
*
4+
* AndroidIDE is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* AndroidIDE is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
subprojects {
19+
plugins.withId("java-library") {
20+
extensions.getByType(JavaPluginExtension::class.java).apply {
21+
sourceCompatibility = JavaVersion.VERSION_17
22+
targetCompatibility = JavaVersion.VERSION_17
23+
}
24+
}
25+
}

build-logic/common/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

build-logic/common/build.gradle.kts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* This file is part of AndroidIDE.
3+
*
4+
* AndroidIDE is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* AndroidIDE is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
19+
20+
plugins {
21+
//noinspection JavaPluginLanguageLevel
22+
id("java-library")
23+
alias(libs.plugins.kotlin.jvm)
24+
}
25+
26+
tasks.withType<KotlinCompile> {
27+
kotlinOptions.jvmTarget = "17"
28+
}
29+
30+
dependencies {
31+
api(gradleApi())
32+
}

build-logic/ide/src/main/java/BuildConfig.kt renamed to build-logic/common/src/main/java/com/itsaky/androidide/build/config/BuildConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
package com.itsaky.androidide.build.config/*
22
* This file is part of AndroidIDE.
33
*
44
* AndroidIDE is free software: you can redistribute it and/or modify

build-logic/ide/src/main/java/CI.kt renamed to build-logic/common/src/main/java/com/itsaky/androidide/build/config/CI.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,24 @@
1515
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
1616
*/
1717

18+
package com.itsaky.androidide.build.config/*
19+
* This file is part of AndroidIDE.
20+
*
21+
* AndroidIDE is free software: you can redistribute it and/or modify
22+
* it under the terms of the GNU General Public License as published by
23+
* the Free Software Foundation, either version 3 of the License, or
24+
* (at your option) any later version.
25+
*
26+
* AndroidIDE is distributed in the hope that it will be useful,
27+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
28+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29+
* GNU General Public License for more details.
30+
*
31+
* You should have received a copy of the GNU General Public License
32+
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
33+
*/
34+
1835
import java.io.File
19-
import org.gradle.kotlin.dsl.provideDelegate
2036

2137
/**
2238
* Information about the CI build.
@@ -33,7 +49,8 @@ object CI {
3349

3450
/** Name of the current branch. */
3551
val branchName by lazy {
36-
System.getenv("GITHUB_REF_NAME") ?: cmdOutput("git", "rev-parse", "--abbrev-ref", "HEAD") // by default, 'main'
52+
System.getenv("GITHUB_REF_NAME") ?: cmdOutput("git", "rev-parse", "--abbrev-ref",
53+
"HEAD") // by default, 'main'
3754
}
3855

3956
/** Whether the current build is a CI build. */

build-logic/ide/src/main/java/FDroidConfig.kt renamed to build-logic/common/src/main/java/com/itsaky/androidide/build/config/FDroidConfig.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@
1515
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
1616
*/
1717

18+
package com.itsaky.androidide.build.config/*
19+
* This file is part of AndroidIDE.
20+
*
21+
* AndroidIDE is free software: you can redistribute it and/or modify
22+
* it under the terms of the GNU General Public License as published by
23+
* the Free Software Foundation, either version 3 of the License, or
24+
* (at your option) any later version.
25+
*
26+
* AndroidIDE is distributed in the hope that it will be useful,
27+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
28+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29+
* GNU General Public License for more details.
30+
*
31+
* You should have received a copy of the GNU General Public License
32+
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
33+
*/
34+
1835
import org.gradle.api.Project
1936
import java.io.File
2037

build-logic/ide/src/main/java/ProjectConfig.kt renamed to build-logic/common/src/main/java/com/itsaky/androidide/build/config/ProjectConfig.kt

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
1616
*/
1717

18+
package com.itsaky.androidide.build.config
19+
1820
import org.gradle.api.Project
1921

2022
/** @author Akash Yadav */
@@ -23,11 +25,11 @@ object ProjectConfig {
2325
const val REPO_HOST = "github.com"
2426
const val REPO_OWNER = "AndroidIDEOfficial"
2527
const val REPO_NAME = "AndroidIDE"
26-
const val REPO_URL = "https://${REPO_HOST}/${REPO_OWNER}/${REPO_NAME}"
28+
const val REPO_URL = "https://$REPO_HOST/$REPO_OWNER/$REPO_NAME"
2729
const val SCM_GIT =
28-
"scm:git:git://${REPO_HOST}/${REPO_OWNER}/${REPO_NAME}.git"
30+
"scm:git:git://$REPO_HOST/$REPO_OWNER/$REPO_NAME.git"
2931
const val SCM_SSH =
30-
"scm:git:ssh://git@${REPO_HOST}/${REPO_OWNER}/${REPO_NAME}.git"
32+
"scm:git:ssh://git@$REPO_HOST/$REPO_OWNER/$REPO_NAME.git"
3133

3234
const val PROJECT_SITE = "https://m.androidide.com"
3335
}
@@ -39,10 +41,10 @@ private var shouldPrintVersionName = true
3941
*/
4042
val Project.isFDroidBuild: Boolean
4143
get() {
42-
if (!FDroidConfig.hasRead) {
43-
FDroidConfig.load(this)
44+
if (!com.itsaky.androidide.build.config.FDroidConfig.hasRead) {
45+
com.itsaky.androidide.build.config.FDroidConfig.load(this)
4446
}
45-
return FDroidConfig.isFDroidBuild
47+
return com.itsaky.androidide.build.config.FDroidConfig.isFDroidBuild
4648
}
4749

4850
val Project.simpleVersionName: String
@@ -52,14 +54,14 @@ val Project.simpleVersionName: String
5254
val regex = Regex("^v\\d+\\.?\\d+\\.?\\d+-\\w+")
5355

5456
val simpleVersion = regex.find(version)?.value?.substring(1)?.also {
55-
if (shouldPrintVersionName) {
57+
if (com.itsaky.androidide.build.config.shouldPrintVersionName) {
5658
logger.warn("Simple version name is '$it' (from version $version)")
57-
shouldPrintVersionName = false
59+
com.itsaky.androidide.build.config.shouldPrintVersionName = false
5860
}
5961
}
6062

6163
if (simpleVersion == null) {
62-
if (CI.isTestEnv) {
64+
if (com.itsaky.androidide.build.config.CI.isTestEnv) {
6365
return "1.0.0-beta"
6466
}
6567

@@ -78,9 +80,9 @@ val Project.projectVersionCode: Int
7880
val regex = Regex("^\\d+\\.?\\d+\\.?\\d+")
7981

8082
val versionCode = regex.find(version)?.value?.replace(".", "")?.toInt()?.also {
81-
if (shouldPrintVersionCode) {
83+
if (com.itsaky.androidide.build.config.shouldPrintVersionCode) {
8284
logger.warn("Version code is '$it' (from version ${version}).")
83-
shouldPrintVersionCode = false
85+
com.itsaky.androidide.build.config.shouldPrintVersionCode = false
8486
}
8587
}
8688
?: throw IllegalStateException(
@@ -100,8 +102,8 @@ val Project.publishingVersion: String
100102
return publishing
101103
}
102104

103-
if (CI.isCiBuild && CI.branchName != "main") {
104-
publishing += "-${CI.commitHash}-SNAPSHOT"
105+
if (com.itsaky.androidide.build.config.CI.isCiBuild && com.itsaky.androidide.build.config.CI.branchName != "main") {
106+
publishing += "-${com.itsaky.androidide.build.config.CI.commitHash}-SNAPSHOT"
105107
}
106108

107109
return publishing
@@ -116,11 +118,11 @@ val Project.publishingVersion: String
116118
*/
117119
val Project.downloadVersion: String
118120
get() {
119-
return if (CI.isCiBuild || isFDroidBuild) {
121+
return if (com.itsaky.androidide.build.config.CI.isCiBuild || isFDroidBuild) {
120122
publishingVersion
121123
} else {
122124
// sometimes, when working locally, Gradle fails to download the latest snapshot version
123125
// this may cause issues while initializing the project in AndroidIDE
124-
VersionUtils.getLatestSnapshotVersion("gradle-plugin")
126+
com.itsaky.androidide.build.config.VersionUtils.getLatestSnapshotVersion("gradle-plugin")
125127
}
126128
}

0 commit comments

Comments
 (0)