Skip to content

Commit 743db18

Browse files
committed
Switched to Gradle convention plugin
1 parent cc64cfb commit 743db18

Some content is hidden

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

46 files changed

+853
-922
lines changed

.github/workflows/build.yaml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,14 @@ jobs:
3939
run: ./gradlew ktlint
4040

4141
# Publish packages
42-
- name: Decode key
43-
if: startsWith(github.ref, 'refs/tags/v0') || startsWith(github.ref, 'refs/tags/v1') || startsWith(github.ref, 'refs/tags/v2') || startsWith(github.ref, 'refs/tags/v3') || startsWith(github.ref, 'refs/tags/v4') || startsWith(github.ref, 'refs/tags/v5') || startsWith(github.ref, 'refs/tags/v6') || startsWith(github.ref, 'refs/tags/v7') || startsWith(github.ref, 'refs/tags/v8') || startsWith(github.ref, 'refs/tags/v9')
44-
run: |
45-
set -euo pipefail
46-
mkdir -p .credentials
47-
echo "$SIGNING_KEY_RING" | base64 -d > ".credentials/$SIGNING_KEY_ID.gpg"
48-
env:
49-
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
50-
SIGNING_KEY_RING: ${{ secrets.SIGNING_KEY_RING }}
5142
- name: Publish package
52-
if: startsWith(github.ref, 'refs/tags/v0') || startsWith(github.ref, 'refs/tags/v1') || startsWith(github.ref, 'refs/tags/v2') || startsWith(github.ref, 'refs/tags/v3') || startsWith(github.ref, 'refs/tags/v4') || startsWith(github.ref, 'refs/tags/v5') || startsWith(github.ref, 'refs/tags/v6') || startsWith(github.ref, 'refs/tags/v7') || startsWith(github.ref, 'refs/tags/v8') || startsWith(github.ref, 'refs/tags/v9')
53-
run: ./gradlew publishToMavenCentral closeAndReleaseMavenCentralStagingRepository
43+
if: startsWith(github.ref, 'refs/tags/v-')
44+
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
5445
env:
5546
PUBLICATION_USERNAME: ${{ secrets.PUBLICATION_USERNAME }}
5647
PUBLICATION_PASSWORD: ${{ secrets.PUBLICATION_PASSWORD }}
5748
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
49+
SIGNING_KEY_RING: ${{ secrets.SIGNING_KEY_RING }}
5850
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
5951

6052
- name: Bundle the build report
@@ -76,7 +68,7 @@ jobs:
7668
contents: read
7769
pages: write
7870
id-token: write
79-
if: startsWith(github.ref, 'refs/heads/_publish') || startsWith(github.ref, 'refs/tags/v0') || startsWith(github.ref, 'refs/tags/v1') || startsWith(github.ref, 'refs/tags/v2') || startsWith(github.ref, 'refs/tags/v3') || startsWith(github.ref, 'refs/tags/v4') || startsWith(github.ref, 'refs/tags/v5') || startsWith(github.ref, 'refs/tags/v6') || startsWith(github.ref, 'refs/tags/v7') || startsWith(github.ref, 'refs/tags/v8') || startsWith(github.ref, 'refs/tags/v9')
71+
if: startsWith(github.ref, 'refs/heads/_publish') || startsWith(github.ref, 'refs/tags/v-')
8072
steps:
8173
- name: Checkout
8274
uses: actions/checkout@v4

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
*.iml
22
.gradle
33
.kotlin
4+
build
45
/local.properties
56
/.credentials
67
/secrets.properties
78
/.idea
8-
/.venv
9-
.DS_Store
10-
/build
11-
*/build
9+
/.venv*
10+
/.ruby*
11+
.DS_Store*
1212
/captures
1313
/docs/reference/
1414
/docs/index.md
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
plugins {
2+
`kotlin-dsl`
3+
id("java-gradle-plugin")
4+
}
5+
6+
dependencies {
7+
api(libs.android.gradle)
8+
api(libs.kotlin.gradle)
9+
api(libs.dokka.gradle)
10+
api(libs.gradleVersions)
11+
}
12+
13+
gradlePlugin {
14+
plugins {
15+
create("com.ensody.build-logic-base") {
16+
id = name
17+
implementationClass = "com.ensody.buildlogic.BuildLogicBasePlugin"
18+
}
19+
}
20+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.ensody.buildlogic
2+
3+
import com.android.build.gradle.BaseExtension
4+
import org.gradle.api.JavaVersion
5+
import org.gradle.api.Project
6+
import org.gradle.api.artifacts.MinimalExternalModuleDependency
7+
import org.gradle.api.provider.Provider
8+
import org.gradle.kotlin.dsl.configure
9+
import org.gradle.kotlin.dsl.dependencies
10+
11+
fun Project.setupAndroid(
12+
coreLibraryDesugaring: Provider<MinimalExternalModuleDependency>?,
13+
javaVersion: JavaVersion = JavaVersion.VERSION_17,
14+
) {
15+
pluginManager.apply("com.android.library")
16+
17+
configure<BaseExtension> {
18+
namespace = "$group.${name.replace('-', '.')}"
19+
val sdk = 35
20+
compileSdkVersion(sdk)
21+
defaultConfig {
22+
minSdk = 21
23+
targetSdk = sdk
24+
versionCode = 1
25+
versionName = project.version as String
26+
// Required for coreLibraryDesugaring
27+
multiDexEnabled = true
28+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
29+
}
30+
31+
compileOptions {
32+
isCoreLibraryDesugaringEnabled = coreLibraryDesugaring != null
33+
sourceCompatibility = javaVersion
34+
targetCompatibility = javaVersion
35+
}
36+
37+
testOptions {
38+
// Needed for Robolectric
39+
unitTests {
40+
isIncludeAndroidResources = true
41+
}
42+
}
43+
44+
packagingOptions {
45+
resources {
46+
pickFirsts.add("META-INF/*.kotlin_module")
47+
pickFirsts.add("META-INF/AL2.0")
48+
pickFirsts.add("META-INF/LGPL2.1")
49+
}
50+
}
51+
}
52+
if (coreLibraryDesugaring != null) {
53+
dependencies {
54+
add("coreLibraryDesugaring", coreLibraryDesugaring)
55+
}
56+
}
57+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
@file:Suppress("UnstableApiUsage")
2+
3+
package com.ensody.buildlogic
4+
5+
import org.gradle.api.Plugin
6+
import org.gradle.api.Project
7+
import org.gradle.api.artifacts.VersionCatalog
8+
import org.gradle.api.artifacts.VersionCatalogsExtension
9+
import org.gradle.kotlin.dsl.getByType
10+
11+
class BuildLogicBasePlugin : Plugin<Project> {
12+
override fun apply(target: Project) {}
13+
}
14+
15+
class BuildLogicBaseDependencies(
16+
val rootProject: Project,
17+
) {
18+
val libs: VersionCatalog = rootProject.extensions.getByType<VersionCatalogsExtension>().named("libs")
19+
}
20+
21+
lateinit var buildLogicBaseDeps: BuildLogicBaseDependencies
22+
23+
fun Project.initBuildLogicBase() {
24+
require(isRootProject) { "initBuildLogic() must be called on the root project!" }
25+
buildLogicBaseDeps = BuildLogicBaseDependencies(this)
26+
version = detectProjectVersion()
27+
println("Version: $version")
28+
subprojects {
29+
version = rootProject.version
30+
}
31+
setupBuildLogicBase()
32+
}
33+
34+
fun Project.setupBuildLogicBase() {
35+
pluginManager.apply("com.ensody.build-logic-base")
36+
setupDependencyUpdates()
37+
38+
if (isRootProject) return
39+
40+
group = (listOf(rootProject.group) + project.path.trimStart(':').split(".").dropLast(1))
41+
.joinToString(".")
42+
}
43+
44+
val libs get() = buildLogicBaseDeps.libs
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.ensody.buildlogic
2+
3+
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
4+
import org.gradle.api.Project
5+
import org.gradle.kotlin.dsl.withType
6+
7+
fun Project.setupDependencyUpdates() {
8+
tasks.withType<DependencyUpdatesTask> {
9+
rejectVersionIf {
10+
isNonStable(candidate.version)
11+
}
12+
}
13+
}
14+
15+
fun isNonStable(version: String): Boolean {
16+
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
17+
val regex = Regex("""[0-9,.v-]+(-r)?""")
18+
return !stableKeyword && regex.matchEntire(version) == null
19+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.ensody.buildlogic
2+
3+
import org.gradle.api.Project
4+
import org.gradle.internal.extensions.core.extra
5+
import org.gradle.kotlin.dsl.dependencies
6+
import org.gradle.kotlin.dsl.getByType
7+
import org.gradle.kotlin.dsl.withType
8+
import org.jetbrains.dokka.gradle.DokkaExtension
9+
import org.jetbrains.dokka.gradle.engine.plugins.DokkaHtmlPluginParameters
10+
import java.time.LocalDate
11+
12+
fun Project.setupDokka(copyright: String) {
13+
plugins.apply("org.jetbrains.dokka")
14+
15+
extra.set(dokkaDoneMarker, true)
16+
17+
if (!isRootProject) {
18+
if (!rootProject.extra.has(dokkaDoneMarker)) {
19+
rootProject.setupDokka(copyright = copyright)
20+
}
21+
rootProject.dependencies {
22+
add("dokka", this@setupDokka)
23+
}
24+
}
25+
extensions.getByType<DokkaExtension>().apply {
26+
dokkaSourceSets.configureEach {
27+
enableAndroidDocumentationLink.set(true)
28+
includes.from(
29+
*fileTree(projectDir) {
30+
includes.addAll(listOf("index.md", "README.md", "Module.md", "docs/*.md"))
31+
}.files.toTypedArray(),
32+
)
33+
}
34+
pluginsConfiguration.withType<DokkaHtmlPluginParameters> {
35+
footerMessage.set("Copyright © ${LocalDate.now().year} $copyright")
36+
}
37+
if (isRootProject) {
38+
dokkaPublications.configureEach {
39+
includes.from(rootProject.file("docs/README.md"))
40+
outputDirectory.set(rootProject.file("build/docs/$name"))
41+
}
42+
}
43+
}
44+
}
45+
46+
private val dokkaDoneMarker = "_dokka_setup_done"

0 commit comments

Comments
 (0)