Skip to content

Commit

Permalink
feat(*): move build.gradle to Kotlin DSL. Also move srtdroid pack…
Browse files Browse the repository at this point in the history
…age to `srtdroid-core`
  • Loading branch information
ThibaultBee committed Jul 9, 2024
1 parent 463b4d5 commit 47a0366
Show file tree
Hide file tree
Showing 103 changed files with 772 additions and 525 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Generate API documentation
if: ${{github.event_name == 'push'}}
run: ./gradlew dokkaHtml
run: ./gradlew dokkaHtmlMultiModule
- name: Deploy API documentation to Github Pages
if: ${{github.event_name == 'push'}}
uses: JamesIves/github-pages-deploy-action@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages
folder: lib/build/dokka/html
folder: build/dokka/htmlMultiModule
47 changes: 0 additions & 47 deletions build.gradle

This file was deleted.

37 changes: 37 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
import org.jetbrains.dokka.DokkaConfiguration.Visibility
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import java.net.URL

plugins {
alias(libs.plugins.androidApplication).apply(false)
alias(libs.plugins.jetbrainsKotlinAndroid).apply(false)
alias(libs.plugins.androidLibrary).apply(false)
alias(libs.plugins.dokka)
}

allprojects {
group = "io.github.thibaultbee.srtdroid"
version = "1.7.0"
}

subprojects {
apply(plugin = "org.jetbrains.dokka")

tasks.withType<DokkaTaskPartial>().configureEach {
dokkaSourceSets.configureEach {
documentedVisibilities.set(
setOf(
Visibility.PUBLIC,
Visibility.PROTECTED
)
)

sourceLink {
localDirectory.set(projectDir.resolve("src"))
remoteUrl.set(URL("https://github.com/ThibaultBee/srtdroid/${project.name}/src"))
remoteLineSuffix.set("#L")
}
}
}
}
1 change: 1 addition & 0 deletions buildSrc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
23 changes: 23 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import org.gradle.kotlin.dsl.`kotlin-dsl`
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
google()
gradlePluginPortal()
}

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "11"
}
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
49 changes: 49 additions & 0 deletions buildSrc/src/main/kotlin/Configuration.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
object AndroidVersions {
const val MIN_SDK = 19
const val TARGET_SDK = 34
const val COMPILE_SDK = 34
}

object Publication {
object Repository {
val username: String?
get() = Property.get(Property.SonatypeUsername)
val password: String?
get() = Property.get(Property.SonatypePassword)
}

object Pom {
const val PACKAGING = "aar"
const val URL = "https://github.com/ThibaultBee/srtdroid"

object Scm {
const val CONNECTION = "scm:git:git://github.com/ThibaultBee/srtdroid.git"
const val DEVELOPER_CONNECTION =
"scm:git:ssh://github.com/ThibaultBee/srtdroid.git"
const val URL = "https://github.com/ThibaultBee/srtdroid"
}

object License {
const val NAME = "Apache License, Version 2.0"
const val URL = "https://www.apache.org/licenses/LICENSE-2.0.txt"
const val DISTRIBUTION = "repo"
}

object Developer {
const val URL = "https://github.com/ThibaultBee"
const val NAME = "Thibault B."
}
}

object Signing {
val hasKey: Boolean
get() = key != null && keyId != null && password != null

val key: String?
get() = Property.get(Property.GpgKey)
val password: String?
get() = Property.get(Property.GpgPassword)
val keyId: String?
get() = Property.get(Property.GpgKeyId)
}
}
12 changes: 12 additions & 0 deletions buildSrc/src/main/kotlin/Property.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
enum class Property(val key: String) {
SonatypeUsername("NEXUS_USERNAME"),
SonatypePassword("NEXUS_PASSWORD"),
GpgKey("GPG_KEY"),
GpgKeyId("GPG_KEY_ID"),
GpgPassword("GPG_PASSWORD");

companion object {
fun get(property: Property): String? =
System.getProperty(property.key) ?: System.getenv(property.key)
}
}
98 changes: 98 additions & 0 deletions buildSrc/src/main/kotlin/Publication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPom
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.the
import org.gradle.plugins.signing.SigningExtension

fun Project.configurePublication() {
apply(plugin = "maven-publish")
apply(plugin = "com.android.library")

the<PublishingExtension>().apply {
publications.create<MavenPublication>("release") {
afterEvaluate {
if (isAndroid) {
from(components.getByName("release"))
} else {
from(components.getByName("java"))
}
}

createPom {
name.set(project.name)
description.set(project.description)
}
}

repositories {
maven {
if (isRelease) {
setUrl("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
} else {
println("Using SNAPSHOT repository")
setUrl("https://oss.sonatype.org/content/repositories/snapshots/")
}

credentials {
username = Publication.Repository.username
password = Publication.Repository.password
}
}
}
}

if (Publication.Signing.hasKey) {
println("Signing publication")
apply(plugin = "signing")

the<SigningExtension>().apply {
useInMemoryPgpKeys(
Publication.Signing.keyId,
Publication.Signing.key,
Publication.Signing.password
)
sign(the<PublishingExtension>().publications)
}
} else {
println("No signing key found. Publication will not be signed.")
}
}

val Project.isRelease: Boolean
get() = version.toString().endsWith("-SNAPSHOT").not()

val Project.isAndroid: Boolean
get() = project.hasProperty("android")

fun MavenPublication.createPom(
configure: MavenPom.() -> Unit = {}
): Unit =
pom {
url.set(Publication.Pom.URL)
packaging = Publication.Pom.PACKAGING

scm {
connection.set(Publication.Pom.Scm.CONNECTION)
developerConnection.set(Publication.Pom.Scm.DEVELOPER_CONNECTION)
url.set(Publication.Pom.Scm.URL)
}

developers {
developer {
name.set(Publication.Pom.Developer.NAME)
url.set(Publication.Pom.Developer.URL)
}
}

licenses {
license {
name.set(Publication.Pom.License.NAME)
url.set(Publication.Pom.License.URL)
distribution.set(Publication.Pom.License.DISTRIBUTION)
}
}
configure()
}
60 changes: 0 additions & 60 deletions example/build.gradle

This file was deleted.

Loading

0 comments on commit 47a0366

Please sign in to comment.