Skip to content

Commit

Permalink
Merge pull request #32 from guardian/ab/publishing/use-nexus-plugin-t…
Browse files Browse the repository at this point in the history
…o-auto-release

Add nexus gradle publish plugin to auto close staging and release
  • Loading branch information
ab-gnm authored May 4, 2024
2 parents a72ceaa + f5e2275 commit d513618
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
AUTOMATED_MAVEN_RELEASE_SONATYPE_PASSWORD: ${{ secrets.AUTOMATED_MAVEN_RELEASE_SONATYPE_PASSWORD }}
run: |
cd android
./gradlew :source:publishAllPublicationsToSonatypeRepository
./gradlew :source:publishToSonatype closeAndReleaseSonatypeStagingRepository
28 changes: 22 additions & 6 deletions android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

# The Source library for Android

> [!Note]
> ~~This is an exploratory project as we evolve Source to support the apps, and the accompanying code infra.~~
### Using the library

Add the library dependency:
The library is available on Maven Central. Add the library dependency to your `build.gradle.kts` file:

```kotlin
implementation("com.gu.source:source-android:0.0.1")
Expand All @@ -17,8 +14,6 @@ See the main [README](../README.md) for using the library.

### Building and using as a bundled repo

~~Please note: This is a temporary solution until we publish the library to mavencentral~~

1. Build the library
Run
```shell
Expand All @@ -32,6 +27,27 @@ See the main [README](../README.md) for using the library.
3. Update the version number in the news app
If the library version has changed, update it in the version catalog for the news app.

### Building and using from maven local

1. Build the library
Run
```shell
./gradlew :source:publishToMavenLocal
```
This will publish the library to your local maven repository.

2. Update the version number in the news app
If the library version has changed, update it in the version catalog for the news app.

3. Ensure you have `mavenLocal` declared first in your repositories
```groovy
repositories {
mavenLocal()
mavenCentral()
google()
}
```

### Other notes

1. We use the `com.gu` package name and group id so we can use the Guardian's Sonatype infra for signing and publishing the library. See [this comment](https://github.com/guardian/source-android/pull/10/files?w=1#r1567071142) for reference.
14 changes: 14 additions & 0 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ plugins {
alias(libs.plugins.kotlinter) apply false
alias(libs.plugins.detekt) apply false
alias(libs.plugins.paparazzi) apply false
alias(libs.plugins.nexus.publish)
}


group = libs.versions.group.get()
version = libs.versions.libraryVersion.get()

nexusPublishing {
repositories {
sonatype {
username = "guardian.automated.maven.release"
password = System.getenv("AUTOMATED_MAVEN_RELEASE_SONATYPE_PASSWORD")
}
}
}

allprojects {
Expand Down
6 changes: 5 additions & 1 deletion android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[versions]
libraryVersion = "0.1.0"
group = "com.gu.source"
libraryVersion = "0.1.1"
compilesdk = "34"
minsdk = "26"
targetsdk = "33"
Expand Down Expand Up @@ -28,6 +29,7 @@ inject = "1"
kotlinx-collections-immutable = "0.3.7"
lifecycleRuntimeKtx = "2.7.0"
lint-gradle = "1.0.0-alpha01"
nexus-publish = "2.0.0"
timber = "5.0.1"

junit = "4.13.2"
Expand Down Expand Up @@ -92,6 +94,8 @@ kotlinter = { id = "org.jmailen.kotlinter", version.ref = "kotlinter" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
paparazzi = { id = "app.cash.paparazzi", version.ref = "paparazzi" }

nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexus-publish" }

# Guardian's convention plugins
guardian-application = { id = "com.theguardian.application", version.ref = "guardian-convention-plugins" }
guardian-library-android = { id = "com.theguardian.library.android", version.ref = "guardian-convention-plugins" }
Expand Down
25 changes: 14 additions & 11 deletions android/source/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

android {
namespace = "com.gu.source"
namespace = libs.versions.group.get()

defaultConfig {
consumerProguardFiles("consumer-rules.pro")
Expand Down Expand Up @@ -39,13 +39,13 @@ dependencies {
publishing {
publications {
register<MavenPublication>("release") {
groupId = "com.gu.source"
groupId = libs.versions.group.get()
artifactId = "source-android"
version = libs.versions.libraryVersion.get()

pom {
name.set("Source Android")
description.set("Guardian design system library for Android")
description.set("The Guardian's design system library for Android")
url.set("https://github.com/guardian/source-apps")
packaging = "aar"
licenses {
Expand Down Expand Up @@ -81,16 +81,19 @@ publishing {
}

repositories {
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = "guardian.automated.maven.release"
password = System.getenv("AUTOMATED_MAVEN_RELEASE_SONATYPE_PASSWORD")
}
}
// This is commented out because we're using nexus publishing plugin to publish to Sonatype.
// That's configured in the root build.gradle.kts file.
// maven {
// name = "sonatype"
// url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
// credentials {
// username = "guardian.automated.maven.release"
// password = System.getenv("AUTOMATED_MAVEN_RELEASE_SONATYPE_PASSWORD")
// }
// }

// Adds a task for publishing locally to the build directory.
// Use as `./gradlew :source:publishReleasePublicationToGusourceRepository`
maven {
name = "gusource"
url = uri("${project.buildDir}/gusource")
Expand Down

0 comments on commit d513618

Please sign in to comment.