-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Publish on Maven Central #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8ef9bc8
8f76e8a
ff2f602
d77166e
8041ef1
6b969c4
aa814b3
939f599
ba3b6a3
5758024
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| name: Publish to Maven Central | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - v* | ||
|
|
||
| jobs: | ||
| publish: | ||
| name: Publish release | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up JDK 17 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: '17' | ||
| distribution: 'temurin' | ||
| cache: gradle | ||
|
|
||
| - name: Publish library to Maven Central | ||
| run: ./gradlew :library:publishAndReleaseToMavenCentral --no-configuration-cache | ||
| env: | ||
| ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} | ||
| ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} | ||
| ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.GPG_KEY_ID }} | ||
| ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_SIGNING_KEY }} | ||
| ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_SIGNING_PASSWORD }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,42 @@ | ||
| import com.vanniktech.maven.publish.SonatypeHost | ||
|
|
||
| plugins { | ||
| id("com.android.library") | ||
| `maven-publish` | ||
| kotlin("android") | ||
| id("com.vanniktech.maven.publish") version "0.29.0" | ||
| } | ||
|
|
||
| val artifact = "crashhandler" | ||
| group = "com.dzeio" | ||
| val projectVersion = project.findProperty("version") as String? ?: "1.1.0" | ||
| version = projectVersion | ||
|
|
||
| publishing { | ||
| publications { | ||
| register<MavenPublication>("release") { | ||
| groupId = group as String? | ||
| artifactId = artifact | ||
| version = projectVersion | ||
|
|
||
| afterEvaluate { | ||
| from(components["release"]) | ||
| } | ||
| // from: https://discuss.kotlinlang.org/t/use-git-hash-as-version-number-in-build-gradle-kts/19818/8 | ||
| fun String.runCommand( | ||
| workingDir: File = File("."), | ||
| timeoutAmount: Long = 60, | ||
| timeoutUnit: TimeUnit = TimeUnit.SECONDS | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶 |
||
| ): String = ProcessBuilder(split("\\s(?=(?:[^'\"`]*(['\"`])[^'\"`]*\\1)*[^'\"`]*$)".toRegex())) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:multiline-expression-wrapping reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-signature reported by reviewdog 🐶 |
||
| .directory(workingDir) | ||
| .redirectOutput(ProcessBuilder.Redirect.PIPE) | ||
| .redirectError(ProcessBuilder.Redirect.PIPE) | ||
| .start() | ||
| .apply { waitFor(timeoutAmount, timeoutUnit) } | ||
| .run { | ||
| val error = errorStream.bufferedReader().readText().trim() | ||
| if (error.isNotEmpty()) { | ||
| return@run "" | ||
| } | ||
| inputStream.bufferedReader().readText().trim() | ||
| } | ||
|
|
||
| val branch = "git rev-parse --abbrev-ref HEAD".runCommand(workingDir = rootDir) | ||
| val tag = "git tag -l --points-at HEAD".runCommand(workingDir = rootDir) | ||
| val commitId = "git rev-parse HEAD".runCommand(workingDir = rootDir) | ||
|
|
||
| val libGroup = "com.dzeio" | ||
| val libArtifact = "crashhandler" | ||
| val libVersion = System.getenv("version") ?: tag.drop(1).ifEmpty { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:multiline-expression-wrapping reported by reviewdog 🐶 |
||
| project.findProperty("VERSION_NAME") as String? ?: "1.1.0" | ||
| } | ||
|
|
||
| android { | ||
| namespace = "$group.$artifact" | ||
| namespace = "$libGroup.$libArtifact" | ||
| compileSdk = 33 | ||
| buildToolsVersion = "33.0.0" | ||
|
|
||
|
|
@@ -37,20 +49,13 @@ android { | |
|
|
||
| testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
| consumerProguardFiles("consumer-rules.pro") | ||
| buildConfigField("String", "VERSION", "\"$projectVersion\"") | ||
| buildConfigField("String", "VERSION", "\"$libVersion\"") | ||
| } | ||
|
|
||
| testFixtures { | ||
| enable = true | ||
| } | ||
|
|
||
| publishing { | ||
| singleVariant("release") { | ||
| withSourcesJar() | ||
| withJavadocJar() | ||
| } | ||
| } | ||
|
|
||
| buildTypes { | ||
| getByName("release") { | ||
| isMinifyEnabled = false | ||
|
|
@@ -65,6 +70,7 @@ android { | |
| sourceCompatibility = JavaVersion.VERSION_11 | ||
| targetCompatibility = JavaVersion.VERSION_11 | ||
| } | ||
|
|
||
| kotlinOptions { | ||
| jvmTarget = "11" | ||
| } | ||
|
|
@@ -75,6 +81,49 @@ android { | |
| } | ||
| } | ||
|
|
||
| mavenPublishing { | ||
| publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) | ||
|
|
||
| signAllPublications() | ||
|
|
||
| coordinates(libGroup, libArtifact, libVersion) | ||
|
|
||
| pom { | ||
| name.set("Crash Handler") | ||
| description.set("An Android library that helps handling and reporting crashes gracefully.") | ||
| url.set("https://github.com/dzeiocom/crashhandler") | ||
| inceptionYear.set("2022") | ||
|
|
||
| licenses { | ||
| license { | ||
| name.set("MIT License") | ||
| url.set("https://github.com/dzeiocom/crashhandler/blob/master/LICENSE") | ||
| distribution.set("repo") | ||
| } | ||
| } | ||
|
|
||
| developers { | ||
| developer { | ||
| id.set("avior") | ||
| name.set("Avior") | ||
| email.set("contact@dze.io") | ||
| url.set("https://github.com/Aviortheking") | ||
| } | ||
| } | ||
|
|
||
| scm { | ||
| url.set("https://github.com/dzeiocom/crashhandler") | ||
| connection.set("scm:git:git://github.com/dzeiocom/crashhandler.git") | ||
| developerConnection.set("scm:git:ssh://git@github.com/dzeiocom/crashhandler.git") | ||
| } | ||
|
|
||
| issueManagement { | ||
| system.set("GitHub Issues") | ||
| url.set("https://github.com/dzeiocom/crashhandler/issues") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| // Necessary for the Activity (well to make it pretty :D) | ||
| implementation("com.google.android.material:material:1.8.0") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [ktlint] standard:final-newline reported by reviewdog 🐶
File must end with a newline (\n)