diff --git a/bom/build.gradle.kts b/bom/build.gradle.kts new file mode 100644 index 0000000..e694774 --- /dev/null +++ b/bom/build.gradle.kts @@ -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) + } +} diff --git a/build-logic/src/main/kotlin/io/github/ackeecz/security/ProjectNames.kt b/build-logic/src/main/kotlin/io/github/ackeecz/security/ProjectNames.kt new file mode 100644 index 0000000..1ff2cc3 --- /dev/null +++ b/build-logic/src/main/kotlin/io/github/ackeecz/security/ProjectNames.kt @@ -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" +} diff --git a/build-logic/src/main/kotlin/io/github/ackeecz/security/plugin/PublishingPlugin.kt b/build-logic/src/main/kotlin/io/github/ackeecz/security/plugin/PublishingPlugin.kt index 259843c..e9de4c1 100644 --- a/build-logic/src/main/kotlin/io/github/ackeecz/security/plugin/PublishingPlugin.kt +++ b/build-logic/src/main/kotlin/io/github/ackeecz/security/plugin/PublishingPlugin.kt @@ -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 @@ -62,6 +63,12 @@ internal class PublishingPlugin : Plugin { 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 { @@ -72,8 +79,13 @@ internal class PublishingPlugin : Plugin { // 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 diff --git a/build-logic/src/main/kotlin/io/github/ackeecz/security/properties/ArtifactProperties.kt b/build-logic/src/main/kotlin/io/github/ackeecz/security/properties/ArtifactProperties.kt index a6bca14..8f9d9ea 100644 --- a/build-logic/src/main/kotlin/io/github/ackeecz/security/properties/ArtifactProperties.kt +++ b/build-logic/src/main/kotlin/io/github/ackeecz/security/properties/ArtifactProperties.kt @@ -1,5 +1,6 @@ package io.github.ackeecz.security.properties +import io.github.ackeecz.security.ProjectNames import java.util.Properties sealed class ArtifactProperties( @@ -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", @@ -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 " + diff --git a/lib.properties b/lib.properties index da96595..1ac171a 100644 --- a/lib.properties +++ b/lib.properties @@ -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 @@ -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 diff --git a/settings.gradle.kts b/settings.gradle.kts index 7ed039f..9671c11 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -28,6 +28,7 @@ enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") rootProject.name = "ackee-security" include(":app") +include(":bom") include(":core") include(":core-internal") include(":datastore")