Skip to content

Commit dcb59bd

Browse files
committed
more gradle
1 parent 861c0d1 commit dcb59bd

File tree

15 files changed

+121
-74
lines changed

15 files changed

+121
-74
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ ij_kotlin_method_parameters_right_paren_on_new_line = true
417417
ij_kotlin_method_parameters_wrap = on_every_item
418418
ij_kotlin_name_count_to_use_star_import = 2147483647
419419
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
420-
ij_kotlin_packages_to_use_import_on_demand = java.util.**
420+
ij_kotlin_packages_to_use_import_on_demand = java.util.**, org.gradle.kotlin.dsl.**
421421
ij_kotlin_parameter_annotation_wrap = off
422422
ij_kotlin_space_after_comma = true
423423
ij_kotlin_space_after_extend_colon = true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ gradle-app.setting
1515
# Local configuration file (sdk path, etc)
1616
local.properties
1717
keystore.properties
18+
github.properties
1819

1920
# Log/OS Files
2021
*.log

BetterBluetoothDeviceSort/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ android {
1212
}
1313
}
1414

15-
dependencies {
16-
}
15+
dependencies {}

DontResetIfBootedAndConnected/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@ android {
1212
}
1313
}
1414

15-
dependencies {
16-
17-
}
15+
dependencies {}

ResetAllNotificationChannels/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,4 @@ android {
1414
}
1515
}
1616

17-
dependencies {
18-
19-
}
17+
dependencies {}

build-logic/convention/build.gradle.kts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ dependencies {
3030
compileOnly(libs.android.gradlePlugin)
3131
compileOnly(libs.android.tools.common)
3232
compileOnly(libs.kotlin.gradlePlugin)
33-
// compileOnly(libs.ksp.gradlePlugin)
3433
implementation(libs.github.api)
3534

3635
// Hack to make the libs accessor work
@@ -40,29 +39,33 @@ dependencies {
4039

4140
gradlePlugin {
4241
plugins {
43-
create("commonAndroidApplicationPlugin") {
42+
register("commonAndroidApplicationPlugin") {
4443
id = "common.android.application"
4544
implementationClass = "CommonAndroidApplication"
4645
}
47-
create("commonAndroidLibraryPlugin") {
46+
register("commonAndroidLibraryPlugin") {
4847
id = "common.android.library"
4948
implementationClass = "CommonAndroidLibrary"
5049
}
51-
create("commonKotlinAndroidPlugin") {
50+
register("commonKotlinAndroidPlugin") {
5251
id = "common.kotlin.android"
5352
implementationClass = "CommonKotlinAndroid"
5453
}
55-
create("commonKotlinJvmPlugin") {
54+
register("commonKotlinJvmPlugin") {
5655
id = "common.kotlin.jvm"
5756
implementationClass = "CommonKotlinJvm"
5857
}
59-
create("commonKotlinMultiplatformPlugin") {
58+
register("commonKotlinMultiplatformPlugin") {
6059
id = "common.kotlin.multiplatform"
6160
implementationClass = "CommonKotlinMultiplatform"
6261
}
63-
create("commonJvmPlugin") {
62+
register("commonJvmPlugin") {
6463
id = "common.jvm"
6564
implementationClass = "CommonJvm"
6665
}
66+
register("commonGithubPlugin") {
67+
id = "common.github"
68+
implementationClass = "GithubPlugin"
69+
}
6770
}
6871
}

build-logic/convention/src/main/kotlin/Common.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class CommonAndroidApplication : Plugin<Project> {
2929
commonAndroid.apply(target)
3030

3131
extensions.configure<ApplicationExtension> {
32-
3332
defaultConfig {
3433
versionCode = getCommitCount()
3534
}
@@ -121,7 +120,6 @@ class CommonAndroidLibrary : Plugin<Project> {
121120
private val commonAndroid = CommonAndroid()
122121

123122
override fun apply(target: Project) {
124-
125123
with(target) {
126124
with(pluginManager) {
127125
apply("com.android.library")
@@ -153,8 +151,8 @@ private class CommonAndroid : Plugin<Project> {
153151
compileSdkVersion(35)
154152

155153
dependencies {
156-
add("implementation", libs.androidx.annotation)
157-
add("implementation", libs.xposed.api)
154+
// add("implementation", libs.androidx.annotation)
155+
add("compileOnly", libs.xposed.api)
158156
}
159157

160158
buildTypes {
@@ -169,8 +167,10 @@ private class CommonAndroid : Plugin<Project> {
169167
lintOptions {
170168
disable += "DiscouragedApi"
171169
disable += "ExpiredTargetSdkVersion"
172-
disable += "OldTargetApi"
173170
disable += "MissingApplicationIcon"
171+
disable += "MissingPermission"
172+
disable += "OldTargetApi"
173+
disable += "PrivateApi"
174174
disable += "UnusedAttribute"
175175
}
176176

@@ -241,7 +241,6 @@ private class CommonKotlin : Plugin<Project> {
241241
}
242242
}
243243

244-
245244
class CommonJvm : Plugin<Project> {
246245
override fun apply(target: Project) {
247246
}
Lines changed: 87 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,74 @@
1+
@file:Suppress("unused")
2+
3+
import java.util.*
14
import buildlogic.git.getAllCommitsPushed
25
import buildlogic.git.getCommitCount
36
import buildlogic.git.getWorkingTreeClean
47
import com.android.build.api.dsl.ApplicationExtension
8+
import org.gradle.BuildAdapter
9+
import org.gradle.BuildResult
510
import org.gradle.api.DefaultTask
11+
import org.gradle.api.Plugin
12+
import org.gradle.api.Project
13+
import org.gradle.api.Transformer
14+
import org.gradle.api.file.RegularFileProperty
15+
import org.gradle.api.provider.Provider
616
import org.gradle.api.tasks.Input
17+
import org.gradle.api.tasks.InputFile
718
import org.gradle.api.tasks.TaskAction
819
import org.gradle.kotlin.dsl.*
920
import org.gradle.work.DisableCachingByDefault
1021
import org.kohsuke.github.GHReleaseBuilder
1122
import org.kohsuke.github.GitHub
1223

13-
@DisableCachingByDefault
14-
abstract class GithubCreateReleaseTask : DefaultTask() {
24+
abstract class GithubPlugin : Plugin<Project> {
1525

16-
init {
17-
notCompatibleWithConfigurationCache("needs to talk to GitHub")
26+
override fun apply(target: Project) {
27+
with(target) {
28+
tasks.register<GithubClearReleaseTask>("githubClearReleases")
29+
subprojects {
30+
afterEvaluate {
31+
if (extensions.findByType<ApplicationExtension>() != null) {
32+
tasks.register<GithubCreateReleaseTask>("githubCreateRelease")
33+
}
34+
}
35+
}
36+
37+
}
1838
}
39+
}
40+
41+
@DisableCachingByDefault
42+
abstract class GithubCreateReleaseTask : Github() {
1943

20-
@get:Input
21-
abstract val repo: String
44+
private val debug = true
2245

23-
@get:Input
24-
abstract val token: String
46+
@Input
47+
val commitCount = project.getCommitCount()
48+
49+
@Input
50+
val workingTreeClean = project.getWorkingTreeClean()
51+
52+
@Input
53+
val allCommitsPushed = project.getAllCommitsPushed()
54+
55+
init {
56+
if (debug || (workingTreeClean && allCommitsPushed)) {
57+
dependsOn("packageRelease")
58+
}
59+
}
2560

2661
@TaskAction
2762
fun createRelease() {
28-
val commitCount = project.getCommitCount()
29-
val workingTreeClean = project.getWorkingTreeClean()
30-
val allCommitsPushed = project.getAllCommitsPushed()
31-
3263
val android = project.extensions.getByType<ApplicationExtension>()
3364

34-
if (workingTreeClean && allCommitsPushed) {
35-
dependsOn("assembleRelease")
65+
if (!debug) {
66+
check(workingTreeClean) { "Commit all changes before creating release" }
67+
check(allCommitsPushed) { "Push to remote before creating release" }
3668
}
3769

38-
check(workingTreeClean) { "Commit all changes before creating release" }
39-
check(allCommitsPushed) { "Push to remote before creating release" }
40-
41-
val packageRelease = project.tasks.getByName("packageRelease")
42-
43-
val outputs = packageRelease.outputs.files
44-
val apks = outputs.filter { it.isDirectory }.flatMap { it.listFiles { file -> file.extension == "apk" }!!.toList() }
45-
46-
val github = GitHub.connectUsingOAuth(token)
47-
val repository = github.getRepository(repo)
70+
val github = GitHub.connectUsingOAuth(token.get())
71+
val repository = github.getRepository(repo.get())
4872

4973
val tagName = "${android.namespace}-v$commitCount"
5074
val name = "${project.name}-v$commitCount"
@@ -58,39 +82,60 @@ abstract class GithubCreateReleaseTask : DefaultTask() {
5882

5983
val release = repository.createRelease(tagName).name(name).draft(true).makeLatest(GHReleaseBuilder.MakeLatest.FALSE).create()
6084

85+
val packageRelease = project.tasks.getByName("packageRelease")
86+
val outputs = packageRelease.outputs.files
87+
val apks = outputs.filter { it.isDirectory }.flatMap { it.listFiles { file -> file.extension == "apk" }.asList() }
6188
apks.forEach {
6289
release.uploadAsset("${project.name}-v$commitCount.apk", it.inputStream(), "application/vnd.android.package-archive")
6390
}
6491

65-
doLast {
66-
project.logger.info("Created release ${release.name}: ${release.htmlUrl}")
67-
}
92+
val logString = "Created release ${release.name}: ${release.htmlUrl}"
93+
94+
project.gradle.addBuildListener(object : BuildAdapter() {
95+
override fun buildFinished(result: BuildResult) {
96+
println(logString)
97+
}
98+
})
6899
}
69100
}
70101

71102
@DisableCachingByDefault
72-
abstract class GithubClearReleaseTask : DefaultTask() {
73-
74-
init {
75-
notCompatibleWithConfigurationCache("needs to talk to GitHub")
76-
}
77-
78-
@get:Input
79-
abstract val repo: String
80-
81-
@get:Input
82-
abstract val token: String
103+
abstract class GithubClearReleaseTask : Github() {
83104

84105
@TaskAction
85106
fun clearReleases() {
86-
87-
val github = GitHub.connectUsingOAuth(token)
88-
val repository = github.getRepository(repo)
107+
val github = GitHub.connectUsingOAuth(token.get())
108+
val repository = github.getRepository(repo.get())
89109

90110
repository.listReleases().filter { it.isDraft }.forEach { release ->
91111
val name = release.name
92112
release.delete()
93-
project.logger.info("Deleted release $name")
113+
println("Deleted release $name")
114+
}
115+
}
116+
}
117+
118+
abstract class Github : DefaultTask() {
119+
120+
init {
121+
notCompatibleWithConfigurationCache("needs to talk to GitHub")
122+
}
123+
124+
@get:InputFile
125+
abstract val configurationFile: RegularFileProperty
126+
127+
@Input
128+
val properties: Provider<Properties> = configurationFile.map { Properties().apply { load(it.asFile.inputStream()) } }
129+
130+
@Input
131+
val repo: Provider<String?> = properties.map<String?>(PropertyFileTransformer("github_repo"))
132+
133+
@Input
134+
val token: Provider<String> = properties.map<String?>(PropertyFileTransformer("github_api_key"))
135+
136+
class PropertyFileTransformer(val key: String) : Transformer<String?, Properties> {
137+
override fun transform(`in`: Properties): String? {
138+
return `in`[key]?.toString()
94139
}
95140
}
96141
}

build-logic/convention/src/main/kotlin/buildlogic/git/Git.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ private fun Project.getCommitCountExec() = providers.exec {
1212
args("rev-list", "--count", "HEAD")
1313
args(projectDir.absolutePath)
1414
args(rootProject.file("gradle").absolutePath)
15+
args(rootProject.file("build-logic"))
1516

1617
rootProject.projectDir.listFiles { file -> file.isFile && file.extension != "md" }!!.forEach { args(it.absolutePath) }
1718

build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,12 @@ plugins {
2121
alias(libs.plugins.kotlin.android) apply false
2222
alias(libs.plugins.kotlin.jvm) apply false
2323
alias(libs.plugins.kotlin.multiplatform) apply false
24+
25+
alias(libs.plugins.buildlogic.github)
26+
}
27+
28+
allprojects {
29+
tasks.withType<Github> {
30+
configurationFile = rootProject.file("github.properties")
31+
}
2432
}

0 commit comments

Comments
 (0)