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

✨ Add BOM #10

Merged
merged 1 commit into from
Dec 2, 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
13 changes: 13 additions & 0 deletions bom/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
`java-platform`
id("ackee.security.publishing")
}

dependencies {
constraints {
api(projects.core)
api(projects.datastore)
api(projects.datastorePreferences)
api(projects.jetpack)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.ackeecz.security

object ProjectNames {

const val BOM_MODULE_NAME = "bom"
const val CORE_MODULE_NAME = "core"
const val CORE_INTERNAL_MODULE_NAME = "core-internal"
const val DATA_STORE_MODULE_NAME = "datastore"
const val DATA_STORE_CORE_MODULE_NAME = "datastore-core"
const val DATA_STORE_CORE_INTERNAL_MODULE_NAME = "datastore-core-internal"
const val DATA_STORE_PREFERENCES_MODULE_NAME = "datastore-preferences"
const val JETPACK_MODULE_NAME = "jetpack"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.github.ackeecz.security.plugin

import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import io.github.ackeecz.security.ProjectNames
import io.github.ackeecz.security.properties.LibraryProperties
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand Down Expand Up @@ -62,6 +63,12 @@ internal class PublishingPlugin : Plugin<Project> {
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
}

excludeTestFixturesFromPublishing()
}
}

private fun Project.excludeTestFixturesFromPublishing() {
if (project.name != ProjectNames.BOM_MODULE_NAME) {
// TODO Using afterEvaluate seems hacky, but even when using AGP DSL like onVariants, the
// component is not available yet and I don't know how to do it better for now
afterEvaluate {
Expand All @@ -72,8 +79,13 @@ internal class PublishingPlugin : Plugin<Project> {
// I didn't figure it out.
val componentName = "release"
val component = project.components.getByName(componentName) as AdhocComponentWithVariants
component.withVariantsFromConfiguration(configurations.getByName("${componentName}TestFixturesVariantReleaseApiPublication")) { skip() }
component.withVariantsFromConfiguration(configurations.getByName("${componentName}TestFixturesVariantReleaseRuntimePublication")) { skip() }
val configurationNames = listOf(
"${componentName}TestFixturesVariantReleaseApiPublication",
"${componentName}TestFixturesVariantReleaseRuntimePublication"
)
configurationNames.forEach { configName ->
component.withVariantsFromConfiguration(configurations.getByName(configName)) { skip() }
}
} catch (_: UnknownConfigurationException) {
// Thrown when the current Project does not support test fixtures, so it does not contain
// configurations above
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.ackeecz.security.properties

import io.github.ackeecz.security.ProjectNames
import java.util.Properties

sealed class ArtifactProperties(
Expand All @@ -22,6 +23,11 @@ sealed class ArtifactProperties(
return properties.getNonNull("${prefix}_$name")
}

class Bom(properties: Properties) : ArtifactProperties(
properties = properties,
defaultPropertyPrefix = "BOM",
)

class Core(properties: Properties) : ArtifactProperties(
properties = properties,
defaultPropertyPrefix = "CORE",
Expand Down Expand Up @@ -69,25 +75,18 @@ sealed class ArtifactProperties(

companion object {

private const val CORE_MODULE_NAME = "core"
private const val CORE_INTERNAL_MODULE_NAME = "core-internal"
private const val DATA_STORE_MODULE_NAME = "datastore"
private const val DATA_STORE_CORE_MODULE_NAME = "datastore-core"
private const val DATA_STORE_CORE_INTERNAL_MODULE_NAME = "datastore-core-internal"
private const val DATA_STORE_PREFERENCES_MODULE_NAME = "datastore-preferences"
private const val JETPACK_MODULE_NAME = "jetpack"

fun getFor(
projectName: String,
properties: Properties,
): ArtifactProperties = when (projectName) {
CORE_MODULE_NAME -> Core(properties)
CORE_INTERNAL_MODULE_NAME -> CoreInternal(properties)
DATA_STORE_MODULE_NAME -> DataStore.Typed(properties)
DATA_STORE_CORE_MODULE_NAME -> DataStore.Core(properties)
DATA_STORE_CORE_INTERNAL_MODULE_NAME -> DataStore.CoreInternal(properties)
DATA_STORE_PREFERENCES_MODULE_NAME -> DataStore.Preferences(properties)
JETPACK_MODULE_NAME -> Jetpack(properties)
ProjectNames.BOM_MODULE_NAME -> Bom(properties)
ProjectNames.CORE_MODULE_NAME -> Core(properties)
ProjectNames.CORE_INTERNAL_MODULE_NAME -> CoreInternal(properties)
ProjectNames.DATA_STORE_MODULE_NAME -> DataStore.Typed(properties)
ProjectNames.DATA_STORE_CORE_MODULE_NAME -> DataStore.Core(properties)
ProjectNames.DATA_STORE_CORE_INTERNAL_MODULE_NAME -> DataStore.CoreInternal(properties)
ProjectNames.DATA_STORE_PREFERENCES_MODULE_NAME -> DataStore.Preferences(properties)
ProjectNames.JETPACK_MODULE_NAME -> Jetpack(properties)
else -> throw IllegalStateException("Unknown Gradle module with name $projectName. Please " +
"add artifact properties for this module and corresponding mapping in " +
"${ArtifactProperties::class.simpleName}. It is also possible that you changed module " +
Expand Down
9 changes: 8 additions & 1 deletion lib.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Common
# Common properties for all artifacts
GROUP_ID=io.github.ackeecz
POM_URL=https://github.com/AckeeCZ/ackee-security
POM_DEVELOPER_ID=ackee
Expand All @@ -10,6 +10,13 @@ POM_SCM_CONNECTION=scm:git:github.com/AckeeCZ/ackee-security.git
POM_SCM_DEVELOPER_CONNECTION=scm:git:ssh://github.com/AckeeCZ/ackee-security.git
POM_SCM_URL=https://github.com/AckeeCZ/ackee-security/tree/main

# BOM
BOM_VERSION=1.0.0
BOM_ARTIFACT_ID=security-bom
BOM_POM_NAME=Ackee Security BOM
BOM_POM_YEAR=2024
BOM_POM_DESCRIPTION=BOM artifact of the Ackee Security library.

# Core artifact
CORE_VERSION=1.0.0
CORE_ARTIFACT_ID=security-core
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
rootProject.name = "ackee-security"

include(":app")
include(":bom")
include(":core")
include(":core-internal")
include(":datastore")
Expand Down