Skip to content

Commit

Permalink
publish to maven central
Browse files Browse the repository at this point in the history
  • Loading branch information
fbzli committed Oct 2, 2024
1 parent 5f826a5 commit 99a0910
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 117 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build Example

on: [ push, workflow_dispatch ]

jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout repository
- name: Checkout
uses: actions/[email protected]

# Setup JDK environment
- name: Set up JDK
uses: actions/[email protected]
with:
distribution: 'zulu'
java-version: '17'

# Run the Gradle Build task
- name: Build Kts Example App
run: ./gradlew clean :examplekts:assemble

# Run the Gradle Build task
- name: Build Groovy Example App
run: ./gradlew clean :examplegroovy:assemble
19 changes: 11 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Plugin to Portal
name: Publish to Maven Central

on:
push:
Expand All @@ -9,13 +9,16 @@ on:
jobs:
publish:
runs-on: ubuntu-latest
env:
GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PLUGIN_PORTAL_PUBLISH_KEY }}
GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PLUGIN_PORTAL_PUBLISH_SECRET }}
steps:
- name: Checkout Repo
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: '17'
- name: Grant permission to execute
run: chmod +x gradlew
- name: Publish on Plugin Portal
run: ./gradlew --project-dir preset setupPluginUploadFromEnvironment publishPlugins -PgithubRefName=${{ github.ref_name }}
- name: Upload
run: |
echo "${{secrets.MAVEN_SIGNING_KEY_ARMOR_ASC}}" > ./signingkey.asc
gpg --quiet --output $GITHUB_WORKSPACE/signingkey.gpg --dearmor ./signingkey.asc
./gradlew :alpaka:plugin:publishAndReleaseToMavenCentral -Psigning.secretKeyRingFile=$GITHUB_WORKSPACE/signingkey.gpg -Psigning.password='${{secrets.MAVEN_SIGNING_KEY_PASSPHRASE}}' -Psigning.keyId=${{secrets.MAVEN_SIGNING_KEY_ID}} -PmavenCentralUsername=${{secrets.MAVEN_CENTRAL_USERNAME}} -PmavenCentralPassword=${{secrets.MAVEN_CENTRAL_PASSWORD}} -PgithubRefName=${{ github.ref_name }}
21 changes: 0 additions & 21 deletions .github/workflows/release_artifactory.yml

This file was deleted.

67 changes: 50 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Alpaka Gradle Plugin

This plugin configures an Android project for build and upload to the Ubique Alpaka backend.
[![Build](https://github.com/UbiqueInnovation/gradle-plugin-alpaka-android/actions/workflows/build.yml/badge.svg)](https://github.com/UbiqueInnovation/gradle-plugin-alpaka-android/actions/workflows/build.yml)
[![Release](https://github.com/UbiqueInnovation/gradle-plugin-alpaka-android/actions/workflows/publish.yml/badge.svg)](https://github.com/UbiqueInnovation/gradle-plugin-alpaka-android/actions/workflows/publish.yml)
[![Maven Central](https://img.shields.io/maven-central/v/ch.ubique.gradle/alpaka.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22ch.ubique.gradle%22%20AND%20a:%22alpaka%22)

Upload your app to the Alpaka App Distribution, label your launcher icon with some flavors, and have some build metadata in the BuildConfig and the Android manifest.

## Functionality

Expand All @@ -15,39 +19,68 @@ The plugin contains the following functionality:

## Configuration

```kotlin
plugins {
id("ch.ubique.gradle.alpaka") version "8.6.0"
}
```

The major and minor version goes in lockstep with the Android Gradle Plugin,
also see [Releases](https://github.com/UbiqueInnovation/gradle-plugin-alpaka-android/releases).

After applying the plugin to your project, you can set the following configuration in your build.gradle.kts:

```kotlin
android {
defaultConfig {
launcherIconLabel = "tescht" // The default icon label per flavor (optional, nullable)
alpakaUploadKey = "..." // The upload key identifying an application in the Alpaka backend
}

productFlavors {
create("dev") {
launcherIconLabel = "tescht" // Modify the default icon label per flavor (optional, nullable)
alpakaUploadKey = "..." // Modify the default uploadKey per flavor (optional)
}
}
defaultConfig {
launcherIconLabel = "tescht" // The default icon label per flavor (optional, nullable)
alpakaUploadKey = "..." // The upload key identifying an application in the Alpaka backend
}

productFlavors {
create("dev") {
launcherIconLabel = "tescht" // Modify the default icon label per flavor (optional, nullable)
alpakaUploadKey = "..." // Modify the default uploadKey per flavor (optional)
}
}
}

alpaka {
changelogCommitCount = 10 // The number of commits to include in the changelog (optional, defaults to 10)
proxy = "host:port" // An optional proxy to set for the upload task. Use for local debugging only
labelAppIcons = false // Globally configure the generateAppIcon tasks to label with flavor name (optional, default is enabled)
changelogCommitCount = 10 // The number of commits to include in the changelog (optional, defaults to 10)
proxy = "host:port" // An optional proxy to set for the upload task. Use for local debugging only
labelAppIcons = false // Globally configure the generateAppIcon tasks to label with flavor name (optional, default is enabled)
}
```

## Build information

These are the build information that are written to the `BuildConfig` class and Android manifest:

| BuildConfig name | Android manifest name | Description | Value |
| BuildConfig field | Android manifest meta-data name | Description | Value |
|-------------------|------------------------------------|--------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| `BUILD_BATCH` | `ch.ubique.alpaka.build.batch` | An ID for a group of builds that belong together (e.g. multiple flavors) | `build_batch` Gradle property, defaults to `0` |
| `BUILD_ID` | `ch.ubique.alpaka.build.id` | An ID for this build | `build_id` or `ubappid` Gradle property, defaults to `localbuild` |
| `BUILD_NUMBER` | `ch.ubique.alpaka.build.number` | An incremental number of this build | `build_number` Gradle property, defaults to `0` |
| `BUILD_TIMESTAMP` | `ch.ubique.alpaka.build.timestamp` | The timestamp of this build | `build_timestamp` Gradle property, defaults to `System.currentTimeMillis()` |
| `BRANCH` | `ch.ubique.alpaka.branch` | The Git branch this build was created from | `branch` Gradle property, defaults to calling the systems Git command line |
| `FLAVOR` | `ch.ubique.alpaka.flavor` | The product flavor this build was created from | Product flavor name of the variant that started the gradle task |
| `FLAVOR` | `ch.ubique.alpaka.flavor` | The product flavor this build was created from | Product flavor name of the variant that started the gradle task |

## Development & Testing

To test any changes to this plugin locally, you can use the example apps shipped with this repository,
or alternatively, deploy an artifact to your local maven repository and include that in an application of your choice:

1. Define a custom version by setting the `VERSION` in alpaka/gradle.properties*
2. You might need to disable `signAllPublications()`*
3. Deploy the plugin artifact by running `./gradlew publishToMavenLocal`
4. Reference `mavenLocal()` in your application's build script's dependency repository list.
5. Apply your local plugin version.

<sup>* do not accidentally commit these changes.</sup>

## Deployment

Create a [Release](https://github.com/UbiqueInnovation/gradle-plugin-alpaka-android/releases),
setting the Tag to the desired version prefixed with a `v`.

Each release on Github will be deployed to Maven Central.
1 change: 0 additions & 1 deletion alpaka/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
alias(libs.plugins.kotlin) apply false
alias(libs.plugins.pluginPublish) apply false
alias(libs.plugins.jfrog.artifactory) apply false
}

allprojects {
Expand Down
29 changes: 25 additions & 4 deletions alpaka/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,29 @@ GROUP=ch.ubique.gradle
ARTIFACT_ID=alpaka
# VERSION will only be used if no property "githubRefName" is set (which the release workflow does)
VERSION=0.0.0
DISPLAY_NAME=Ubique Alpaka
DESCRIPTION=Adds tasks to apply flavor-specific icon overlays, inject build metadata into the Android manifest and upload the APK to the Ubique Alpaka backend
WEBSITE=https://github.com/UbiqueInnovation/gradle-plugin-alpaka-android
VCS_URL=https://github.com/UbiqueInnovation/gradle-plugin-alpaka-android
IMPLEMENTATION_CLASS=ch.ubique.gradle.alpaka.AlpakaPlugin

# POM metadata
POM_NAME=alpaka
POM_PACKAGING=jar
POM_DESCRIPTION=Upload your app to the Alpaka App Distribution, label your launcher icon with some flavors, and have some build metadata in the BuildConfig and the Android manifest.
POM_INCEPTION_YEAR=2024

# POM URLs
POM_URL=https://github.com/UbiqueInnovation/gradle-plugin-alpaka-android
POM_SCM_URL=https://github.com/UbiqueInnovation/gradle-plugin-alpaka-android
POM_SCM_CONNECTION=scm:[email protected]:UbiqueInnovation/gradle-plugin-alpaka-android.git
POM_SCM_DEV_CONNECTION=scm:[email protected]:UbiqueInnovation/gradle-plugin-alpaka-android.git

# License information
POM_LICENCE_NAME=License
POM_LICENCE_URL=https://github.com/UbiqueInnovation/gradle-plugin-alpaka-android/blob/main/LICENSE
POM_LICENCE_DIST=repo

# Developer information
POM_DEVELOPER_ID=UbiqueInnovation
POM_DEVELOPER_NAME=Ubique Innovation
POM_DEVELOPER_URL=https://www.ubique.ch/

# Sonatype metadata
SONATYPE_STAGING_PROFILE=ch.ubique
63 changes: 8 additions & 55 deletions alpaka/plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.vanniktech.maven.publish.GradlePublishPlugin
import com.vanniktech.maven.publish.SonatypeHost
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
Expand All @@ -7,7 +9,7 @@ plugins {
kotlin("jvm")
`java-gradle-plugin`
alias(libs.plugins.pluginPublish)
alias(libs.plugins.jfrog.artifactory)
alias(libs.plugins.vanniktech)
}

dependencies {
Expand Down Expand Up @@ -43,64 +45,15 @@ gradlePlugin {
id = property("ID").toString()
implementationClass = property("IMPLEMENTATION_CLASS").toString()
version = project.version
description = property("DESCRIPTION").toString()
displayName = property("DISPLAY_NAME").toString()
tags = listOf("android", "ubique")
}
}
website.set(property("WEBSITE").toString())
vcsUrl.set(property("VCS_URL").toString())
}

tasks.create("setupPluginUploadFromEnvironment") {
doLast {
val key = System.getenv("GRADLE_PUBLISH_KEY")
val secret = System.getenv("GRADLE_PUBLISH_SECRET")

if (key == null || secret == null) {
throw GradleException("gradlePublishKey and/or gradlePublishSecret are not defined environment variables")
}

System.setProperty("gradle.publish.key", key)
System.setProperty("gradle.publish.secret", secret)
}
}

// MAVEN PUBLISHING

publishing {
publications {
register<MavenPublication>("mavenJava") {
from(components.getByName("java"))
artifactId = property("ARTIFACT_ID").toString()
groupId = property("GROUP").toString()
version = project.version.toString()
}
}
}

artifactory {
val url = System.getenv("UB_ARTIFACTORY_URL") ?: project.property("ubiqueMavenRootUrl")?.toString()
setContextUrl(url)
publish {
repository {
repoKey = System.getenv("UB_ARTIFACTORY_REPO_ANDROID") ?: project.property("ubiqueMavenRepoName")?.toString()
username = System.getenv("UB_ARTIFACTORY_USER") ?: project.property("ubiqueMavenUser")?.toString()
password = System.getenv("UB_ARTIFACTORY_PASSWORD") ?: project.property("ubiqueMavenPass")?.toString()
}

defaults {
publications("mavenJava")
setPublishArtifacts(true)
setProperties(
mapOf(
"build.status" to this.project.status.toString()
)
)
setPublishPom(true)
setPublishIvy(false)
}
}
mavenPublishing {
configure(GradlePublishPlugin())
coordinates(property("GROUP").toString(), property("ARTIFACT_ID").toString(), project.version.toString())
publishToMavenCentral(SonatypeHost.S01, true)
signAllPublications()
}

// enable test logging with gradle
Expand Down
2 changes: 1 addition & 1 deletion examplegroovy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
minSdk 26
targetSdk 34
versionCode 1
versionName "1.0"
versionName project.version.toString()

alpakaUploadKey = "defaultConfig upload key"
}
Expand Down
3 changes: 1 addition & 2 deletions examplekts/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ android {
minSdk = 26
targetSdk = 34
versionCode = 1
versionName = "1.0"
versionName = project.version.toString()

alpakaUploadKey = "defaultConfig upload key"
}
Expand Down Expand Up @@ -66,7 +66,6 @@ dependencies {
implementation(libs.appcompat)
implementation(libs.material)
implementation(libs.activity)
implementation(libs.activity)
}

alpaka {
Expand Down
13 changes: 5 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[versions]
agp = "8.6.1"
kotlin = "2.0.20"
pluginPublish = "1.2.2"
coroutines = "1.8.1"
vanniktech = "0.29.0"

okhttp = "4.12.0"
retrofit = "2.11.0"
moshi = "1.15.1"
agp = "8.6.1"
jfrog-artifactory = "5.1.10"

coreKtx = "1.13.1"
appcompat = "1.7.0"
Expand All @@ -19,12 +19,9 @@ kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin"}
pluginPublish = { id = "com.gradle.plugin-publish", version.ref = "pluginPublish"}
androidApplication = { id = "com.android.application", version.ref = "agp" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
jfrog-artifactory = { id = "com.jfrog.artifactory", version.ref = "jfrog-artifactory" }
vanniktech = { id = "com.vanniktech.maven.publish", version.ref = "vanniktech" }

[libraries]
junit = "junit:junit:4.13.2"

coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp"}
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit"}
retrofitConverterScalars = { module = "com.squareup.retrofit2:converter-scalars", version.ref = "retrofit"}
Expand All @@ -40,4 +37,4 @@ material = { group = "com.google.android.material", name = "material", version.r
activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }


junit = "junit:junit:4.13.2"
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ dependencyResolutionManagement {
}
}

rootProject.name = "gradle-plugin-alpaka-android"

includeBuild("alpaka")
include(":examplekts")
include(":examplegroovy")

0 comments on commit 99a0910

Please sign in to comment.