Skip to content

Commit e4428ba

Browse files
committed
chore(build): Introduce convention plugins
1 parent 30d8613 commit e4428ba

File tree

10 files changed

+257
-151
lines changed

10 files changed

+257
-151
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ android {
5151
}
5252
kotlin {
5353
compilerOptions {
54-
jvmTarget = JvmTarget.fromTarget("11")
54+
jvmTarget = JvmTarget.JVM_11
5555
}
5656
}
5757
buildFeatures {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2025 Harry Timothy Tumalewa
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
18+
19+
plugins {
20+
`kotlin-dsl`
21+
}
22+
23+
group = "com.harrytmthy.safebox.buildlogic"
24+
25+
java {
26+
sourceCompatibility = JavaVersion.VERSION_17
27+
targetCompatibility = JavaVersion.VERSION_17
28+
}
29+
30+
kotlin {
31+
compilerOptions {
32+
jvmTarget = JvmTarget.JVM_17
33+
}
34+
}
35+
36+
dependencies {
37+
compileOnly(libs.android.gradle)
38+
compileOnly(libs.dokka.gradle)
39+
compileOnly(libs.kotlin.gradle)
40+
compileOnly(libs.maven.publish)
41+
}
42+
43+
tasks {
44+
validatePlugins {
45+
enableStricterValidation = true
46+
failOnWarning = true
47+
}
48+
}
49+
50+
gradlePlugin {
51+
plugins {
52+
register("safeBoxAndroidLibrary") {
53+
id = libs.plugins.safebox.android.library.get().pluginId
54+
implementationClass = "AndroidLibraryConventionPlugin"
55+
}
56+
register("safeBoxPublishing") {
57+
id = libs.plugins.safebox.publishing.get().pluginId
58+
implementationClass = "PublishingConventionPlugin"
59+
}
60+
}
61+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2025 Harry Timothy Tumalewa
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import com.android.build.gradle.LibraryExtension
18+
import org.gradle.api.JavaVersion
19+
import org.gradle.api.Plugin
20+
import org.gradle.api.Project
21+
import org.gradle.kotlin.dsl.apply
22+
import org.gradle.kotlin.dsl.assign
23+
import org.gradle.kotlin.dsl.configure
24+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
25+
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
26+
27+
class AndroidLibraryConventionPlugin : Plugin<Project> {
28+
29+
override fun apply(target: Project) {
30+
with(target) {
31+
apply(plugin = "com.android.library")
32+
apply(plugin = "org.jetbrains.kotlin.android")
33+
extensions.configure<LibraryExtension> {
34+
compileSdk = 36
35+
defaultConfig {
36+
minSdk = 23
37+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
38+
}
39+
buildTypes {
40+
named("release") {
41+
isMinifyEnabled = false
42+
}
43+
}
44+
compileOptions {
45+
sourceCompatibility = JavaVersion.VERSION_11
46+
targetCompatibility = JavaVersion.VERSION_11
47+
}
48+
}
49+
extensions.configure<KotlinAndroidProjectExtension> {
50+
compilerOptions.jvmTarget = JvmTarget.JVM_11
51+
}
52+
}
53+
}
54+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2025 Harry Timothy Tumalewa
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import com.vanniktech.maven.publish.MavenPublishBaseExtension
18+
import com.vanniktech.maven.publish.SonatypeHost
19+
import org.gradle.api.Plugin
20+
import org.gradle.api.Project
21+
import org.gradle.kotlin.dsl.configure
22+
23+
class PublishingConventionPlugin : Plugin<Project> {
24+
25+
override fun apply(target: Project) {
26+
with(target) {
27+
group = "io.github.harrytmthy"
28+
version = "1.3.0-alpha01"
29+
30+
pluginManager.apply("org.jetbrains.dokka")
31+
pluginManager.apply("com.vanniktech.maven.publish")
32+
extensions.configure<MavenPublishBaseExtension> {
33+
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
34+
signAllPublications()
35+
pom {
36+
url.set("https://github.com/harrytmthy/safebox")
37+
licenses {
38+
license {
39+
name.set("MIT License")
40+
url.set("https://opensource.org/licenses/MIT")
41+
}
42+
}
43+
developers {
44+
developer {
45+
id.set("harrytmthy")
46+
name.set("Harry Timothy Tumalewa")
47+
email.set("harrytmthy@gmail.com")
48+
}
49+
}
50+
scm {
51+
connection.set("scm:git:git://github.com/harrytmthy/safebox.git")
52+
developerConnection.set("scm:git:ssh://github.com:harrytmthy/safebox.git")
53+
url.set("https://github.com/harrytmthy/safebox")
54+
}
55+
}
56+
}
57+
}
58+
}
59+
}

build-logic/gradle.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Gradle properties are not passed to included builds https://github.com/gradle/gradle/issues/2534
2+
org.gradle.caching=true
3+
org.gradle.configureondemand=true
4+
org.gradle.configuration-cache=true
5+
org.gradle.configuration-cache.parallel=true
6+
org.gradle.parallel=true

build-logic/settings.gradle.kts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2025 Harry Timothy Tumalewa
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
pluginManagement {
18+
repositories {
19+
gradlePluginPortal()
20+
google()
21+
}
22+
}
23+
24+
dependencyResolutionManagement {
25+
repositories {
26+
google {
27+
content {
28+
includeGroupByRegex("com\\.android.*")
29+
includeGroupByRegex("com\\.google.*")
30+
includeGroupByRegex("androidx.*")
31+
}
32+
}
33+
mavenCentral()
34+
}
35+
versionCatalogs {
36+
create("libs") {
37+
from(files("../gradle/libs.versions.toml"))
38+
}
39+
}
40+
}
41+
42+
rootProject.name = "build-logic"
43+
include(":convention")

gradle/libs.versions.toml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,22 @@ protobuf-protoc = { group = "com.google.protobuf", name = "protoc", version.ref
5252
safebox = { group = "io.github.harrytmthy", name = "safebox", version.ref = "safebox" }
5353
timber = { group = "com.jakewharton.timber", name = "timber", version.ref = "timber" }
5454

55+
# Dependencies of build-logic
56+
android-gradle = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" }
57+
dokka-gradle = { group = "org.jetbrains.dokka", name = "dokka-gradle-plugin", version.ref = "dokka" }
58+
kotlin-gradle = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
59+
maven-publish = { group = "com.vanniktech", name = "gradle-maven-publish-plugin", version.ref = "mavenPublishPlugin" }
60+
5561
[plugins]
5662
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
5763
android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" }
5864
compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
5965
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
6066
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
6167
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
62-
maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublishPlugin"}
63-
protobuf = { id = "com.google.protobuf", version.ref = "protobufPlugin" }
68+
maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublishPlugin" }
69+
protobuf = { id = "com.google.protobuf", version.ref = "protobufPlugin" }
70+
71+
# Convention Plugins
72+
safebox-android-library = { id = "safebox.android.library" }
73+
safebox-publishing = { id = "safebox.publishing" }

safebox-crypto/build.gradle.kts

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,18 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import com.vanniktech.maven.publish.SonatypeHost
17-
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
1816

1917
plugins {
20-
id("com.android.library")
21-
id("org.jetbrains.kotlin.android")
22-
id("org.jetbrains.dokka")
23-
id("com.vanniktech.maven.publish")
18+
alias(libs.plugins.safebox.android.library)
19+
alias(libs.plugins.safebox.publishing)
2420
}
2521

26-
group = "io.github.harrytmthy"
27-
version = "1.3.0-alpha01"
28-
2922
android {
3023
namespace = "com.harrytmthy.safebox.cryptography"
31-
compileSdk = 36
3224

3325
defaultConfig {
34-
minSdk = 23
35-
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3626
consumerProguardFiles("proguard-consumer-rules.pro")
3727
}
38-
39-
buildTypes {
40-
release {
41-
isMinifyEnabled = false
42-
}
43-
}
44-
45-
compileOptions {
46-
sourceCompatibility = JavaVersion.VERSION_11
47-
targetCompatibility = JavaVersion.VERSION_11
48-
}
49-
50-
kotlin {
51-
compilerOptions {
52-
jvmTarget = JvmTarget.fromTarget("11")
53-
}
54-
}
5528
}
5629

5730
dependencies {
@@ -65,52 +38,9 @@ dependencies {
6538
androidTestImplementation(libs.kotlin.test)
6639
}
6740

68-
dokka {
69-
dokkaSourceSets {
70-
configureEach {
71-
includes.from("README.md")
72-
}
73-
}
74-
}
75-
76-
tasks.register<Jar>("sourcesJar") {
77-
archiveClassifier.set("sources")
78-
from(android.sourceSets["main"].java.srcDirs)
79-
}
80-
81-
tasks.register<Jar>("javadocJar") {
82-
dependsOn("dokkaJavadoc")
83-
archiveClassifier.set("javadoc")
84-
from(tasks.named("dokkaJavadoc").map { it.outputs.files })
85-
}
86-
8741
mavenPublishing {
88-
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
89-
signAllPublications()
90-
9142
pom {
9243
name.set("SafeBox Crypto")
9344
description.set("Cryptography core used by SafeBox, including ChaCha20-Poly1305 and AES-GCM keystore wrapping.")
94-
url.set("https://github.com/harrytmthy/safebox")
95-
96-
licenses {
97-
license {
98-
name.set("MIT License")
99-
url.set("https://opensource.org/licenses/MIT")
100-
}
101-
}
102-
103-
developers {
104-
developer {
105-
id.set("harrytmthy")
106-
name.set("Harry Timothy Tumalewa")
107-
email.set("harrytmthy@gmail.com")
108-
}
109-
}
110-
scm {
111-
connection.set("scm:git:git://github.com/harrytmthy/safebox.git")
112-
developerConnection.set("scm:git:ssh://github.com:harrytmthy/safebox.git")
113-
url.set("https://github.com/harrytmthy/safebox")
114-
}
11545
}
11646
}

0 commit comments

Comments
 (0)