Skip to content
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

Improve publishing configuration #468

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
dependencies {
api(libs.android.gradle.api)
}
19 changes: 19 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/

dependencyResolutionManagement {
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS

repositories {
google()
mavenCentral()
}

versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
5 changes: 0 additions & 5 deletions buildSrc/src/main/java/VersionConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ object VersionConfig {
private val ENV_VERSION_NAME: String? = System.getenv("VERSION_NAME")
private val versionOnlyRegex = "[0-9]+.[0-9].[0-9]".toRegex()

/**
* Maven artifact group
*/
const val GROUP = "ch.srgssr.pillarbox"

/**
* Version name
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
package ch.srgssr.pillarbox.gradle

import VersionConfig
import com.android.build.api.dsl.LibraryExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.register

/**
* Custom Gradle plugin to manage publication of a Pillarbox's library modules.
*/
class PillarboxPublishingPlugin : Plugin<Project> {
override fun apply(target: Project) = with(target) {
pluginManager.apply("com.android.library")
pluginManager.apply("org.gradle.maven-publish")

extensions.configure<LibraryExtension> {
defaultConfig {
group = "ch.srgssr.pillarbox"
version = VersionConfig.versionName()
}

publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}
}

extensions.configure<PublishingExtension> {
publications {
register<MavenPublication>("gpr") {
afterEvaluate {
from(components["release"])
}
}
}

repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/SRGSSR/pillarbox-android")
credentials {
username = findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
password = findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
implementation-class=ch.srgssr.pillarbox.gradle.PillarboxPublishingPlugin
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ turbine = "1.0.0"

[libraries]
accompanist-navigation-material = { module = "com.google.accompanist:accompanist-navigation-material", version.ref = "accompanist" }
android-gradle-api = { module = "com.android.tools.build:gradle-api", version.ref = "android-gradle-plugin" }
androidx-activity = { module = "androidx.activity:activity", version.ref = "androidx-activity" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" }
androidx-activity-ktx = { module = "androidx.activity:activity-ktx", version.ref = "androidx-activity" }
Expand Down
39 changes: 6 additions & 33 deletions pillarbox-analytics/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

/*
* Copyright (c) SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/

import ch.srgssr.pillarbox.gradle.PillarboxPublishingPlugin
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlinx.kover)
`maven-publish`
}

apply<PillarboxPublishingPlugin>()

android {
namespace = "ch.srgssr.pillarbox.analytics"
compileSdk = AppConfig.compileSdk

defaultConfig {
minSdk = AppConfig.minSdk
version = VersionConfig.versionName()
group = VersionConfig.GROUP

buildConfigField("String", "BUILD_DATE", "\"${AppConfig.getBuildDate()}\"")
buildConfigField("String", "VERSION_NAME", "\"${version}\"")
Expand Down Expand Up @@ -47,12 +48,6 @@ android {
buildConfig = true
resValues = false
}
publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}
testOptions {
unitTests {
isIncludeAndroidResources = true
Expand Down Expand Up @@ -90,25 +85,3 @@ koverReport {
}
}
}

publishing {

publications {
register<MavenPublication>("gpr") {
afterEvaluate {
from(components["release"])
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/SRGSSR/pillarbox-android")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
password =
project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
}
}
}
}
38 changes: 6 additions & 32 deletions pillarbox-core-business/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

/*
* Copyright (c) SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/

import ch.srgssr.pillarbox.gradle.PillarboxPublishingPlugin
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.kotlinx.kover)
`maven-publish`
}

apply<PillarboxPublishingPlugin>()

android {
namespace = "ch.srgssr.pillarbox.core.business"
compileSdk = AppConfig.compileSdk

defaultConfig {
minSdk = AppConfig.minSdk
version = VersionConfig.versionName()
group = VersionConfig.GROUP

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand All @@ -42,12 +43,6 @@ android {
buildConfig = true
resValues = false
}
publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}
testOptions {
unitTests {
isIncludeAndroidResources = true
Expand Down Expand Up @@ -108,24 +103,3 @@ koverReport {
}
}
}

publishing {
publications {
register<MavenPublication>("gpr") {
afterEvaluate {
from(components["release"])
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/SRGSSR/pillarbox-android")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
password =
project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
}
}
}
}
38 changes: 6 additions & 32 deletions pillarbox-player/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

/*
* Copyright (c) SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/

import ch.srgssr.pillarbox.gradle.PillarboxPublishingPlugin
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlinx.kover)
`maven-publish`
}

apply<PillarboxPublishingPlugin>()

android {
namespace = "ch.srgssr.pillarbox.player"
compileSdk = AppConfig.compileSdk

defaultConfig {
minSdk = AppConfig.minSdk
version = VersionConfig.versionName()
group = VersionConfig.GROUP

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFile("consumer-rules.pro")
Expand All @@ -44,12 +45,6 @@ android {
buildConfig = true
resValues = false
}
publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}

// Mockk includes some licenses information, which may conflict with other license files. This block merges all licenses together.
// Mockk excludes all licenses instead:
Expand Down Expand Up @@ -118,24 +113,3 @@ koverReport {
}
}
}

publishing {
publications {
register<MavenPublication>("gpr") {
afterEvaluate {
from(components["release"])
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/SRGSSR/pillarbox-android")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
password =
project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
}
}
}
}
38 changes: 6 additions & 32 deletions pillarbox-ui/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

/*
* Copyright (c) SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/

import ch.srgssr.pillarbox.gradle.PillarboxPublishingPlugin
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlinx.kover)
`maven-publish`
}

apply<PillarboxPublishingPlugin>()

android {
namespace = "ch.srgssr.pillarbox.ui"
compileSdk = AppConfig.compileSdk

defaultConfig {
minSdk = AppConfig.minSdk
version = VersionConfig.versionName()
group = VersionConfig.GROUP

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFile("consumer-rules.pro")
Expand All @@ -44,12 +45,6 @@ android {
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get()
}
publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}
}

tasks.withType<Test>().configureEach {
Expand Down Expand Up @@ -90,24 +85,3 @@ koverReport {
}
}
}

publishing {
publications {
register<MavenPublication>("gpr") {
afterEvaluate {
from(components["release"])
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/SRGSSR/pillarbox-android")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
password =
project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
}
}
}
}
Loading