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 to manage faker versions #227

Merged
merged 9 commits into from
Mar 29, 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
133 changes: 67 additions & 66 deletions CHANGELOG.adoc

Large diffs are not rendered by default.

19 changes: 1 addition & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ pre-release-major: ## publishes next pre-release version with a major version bu
-Prelease -PpreRelease -Pincrement=major \
--info

git push origin --tags

.PHONY: pre-release-minor
pre-release-minor: ## publishes next pre-release with a minor version bump
./gradlew test integrationTest \
Expand All @@ -90,8 +88,6 @@ pre-release-minor: ## publishes next pre-release with a minor version bump
-Prelease -PpreRelease -Pincrement=minor \
--info

git push origin --tags

.PHONY: pre-release-patch
pre-release-patch: ## publishes next pre-release with a patch version bump
./gradlew test integrationTest \
Expand All @@ -102,8 +98,6 @@ pre-release-patch: ## publishes next pre-release with a patch version bump
-Prelease -PpreRelease -Pincrement=patch \
--info

git push origin --tags

.PHONY: next-pre-release
next-pre-release: ## publishes next pre-release version
./gradlew test integrationTest \
Expand All @@ -114,8 +108,6 @@ next-pre-release: ## publishes next pre-release version
-Prelease -Pincrement=pre_release \
--info

git push origin --tags

.PHONY: promote-to-release
promote-to-release: ## publishes next release from the current pre-release version
./gradlew test integrationTest \
Expand All @@ -126,8 +118,6 @@ promote-to-release: ## publishes next release from the current pre-release versi
-Prelease -PpromoteRelease \
--info

git push origin --tags

.PHONY: release-major
release-major: ## publishes next major release version
./gradlew test integrationTest \
Expand All @@ -138,20 +128,16 @@ release-major: ## publishes next major release version
-Prelease -Pincrement=major \
--info

git push origin --tags

.PHONY: release-minor
release-minor: ## publishes next minor release version
./gradlew test integrationTest \
tag \
nativeCompile \
publishToSonatype \
closeSonatypeStagingRepository \
tag \
-Prelease -Pincrement=minor \
--info

git push origin --tags

.PHONY: release-patch
release-patch: ## publishes next patch release version
./gradlew test integrationTest \
Expand All @@ -162,8 +148,6 @@ release-patch: ## publishes next patch release version
-Prelease -Pincrement=patch \
--info

git push origin --tags

.PHONY: release
release: check_java ## publishes the next release with a specified VERSION
@:$(call check_defined, VERSION, semantic version string - 'X.Y.Z(-rc.\d+)?')
Expand All @@ -178,7 +162,6 @@ release: check_java ## publishes the next release with a specified VERSION
./gradlew publishToSonatype closeSonatypeStagingRepository -Pversion=$(VERSION) --info
# create and push git tag
git tag v$(VERSION)
git push origin --tags

.PHONY: help
help: ## Displays this help
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ Port of a popular ruby [faker](https://github.com/stympy/faker) gem written in k

Documentation for kotlin-faker is available at [serpro69.github.io/kotlin-faker/](https://serpro69.github.io/kotlin-faker/).

_NB! The documentation website is currently not versioned and always reflects `master` rather than the last stable version._

> [!WARNING]
> **kotlin-faker 2.0** is coming, which, apart from new features, also means breaking changes.
>
> Presently this will affect users of snapshot versions, which are built from 'master'.
>
> More details on currently added breaking changes and migration can be found in [#220](https://github.com/serpro69/kotlin-faker/issues/220)

### Downloading
Expand Down
66 changes: 66 additions & 0 deletions bom/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## `kotlin-faker-bom`

[![Maven Central](https://img.shields.io/maven-central/v/io.github.serpro69/kotlin-faker-bom?style=for-the-badge)](https://search.maven.org/artifact/io.github.serpro69/kotlin-faker-bom)
[![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/io.github.serpro69/kotlin-faker-bom?label=snapshot-version&server=https%3A%2F%2Foss.sonatype.org&style=for-the-badge&color=yellow)](#downloading)

Kotlin-faker provides a [Bill-of-Materials](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms) that simplifies dependency management.

## Usage

Documentation for kotlin-faker is available at [serpro69.github.io/kotlin-faker/](https://serpro69.github.io/kotlin-faker/).

### Downloading

Latest releases are always available on maven central.

**With gradle**

To [import Maven BOM with Gradle](https://docs.gradle.org/current/userguide/platforms.html#sub:bom_import), a platform dependency needs to be declared on the `kotlin-faker-bom`. The rest of `kotlin-faker` dependencies do not need to specify the versions explicitly as they will be pulled from the BOM

```groovy
dependencies {
implementation platform('io.github.serpro69:kotlin-faker-bom:$version')
implementation 'io.github.serpro69:kotlin-faker'
implementation 'io.github.serpro69:kotlin-faker-books'
implementation 'io.github.serpro69:kotlin-faker-tech'
// rest of dependencies
}
```

**With maven**

To use the BOM, a dependency on `kotlin-faker-bom` needs to be declared in the `<dependencyManagement>` block of the `pom.xml`, file:

```xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.github.serpro69</groupId>
<artifactId>kotlin-faker-bom</artifactId>
<version>${kotlin-faker.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
```

Then add the dependencies as usual but w/o specifying the versions, which will be pulled from the BOM:

```xml
<dependencies>
<dependency>
<groupId>io.github.serpro69</groupId>
<artifactId>kotlin-faker</artifactId>
</dependency>
<dependency>
<groupId>io.github.serpro69</groupId>
<artifactId>kotlin-faker-books</artifactId>
</dependency>
<dependency>
<groupId>io.github.serpro69</groupId>
<artifactId>kotlin-faker-tech</artifactId>
</dependency>
<!-- rest of dependencies as needed -->
</dependencies>
```
111 changes: 111 additions & 0 deletions bom/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import io.github.serpro69.semverkt.gradle.plugin.tasks.TagTask

plugins {
`java-platform`
`maven-publish`
signing
}

val bom = project
val isSnapshot = provider {
version.toString().startsWith("0.0.0")
|| version.toString().endsWith("SNAPSHOT")
}
val newTag = provider {
val tag = project.tasks.getByName("tag", TagTask::class)
/* ':bom' shares the tag with 'root', ':cli-bot' and ':core' modules,
and hence the tag might already exist and didWork will return false for ':bom' */
tag.didWork || tag.tagExists
}

// Exclude subprojects that will never be published so that when configuring this project
// we don't force their configuration and do unnecessary work
val excludeFromBom = listOf("test")
fun projectsFilter(candidateProject: Project) =
excludeFromBom.all { !candidateProject.name.contains(it) } &&
candidateProject.name != bom.name

// Declare that this subproject depends on all subprojects matching the filter
// When this subproject is configured, it will force configuration of all subprojects
// so that we can declare dependencies on them
rootProject.subprojects.filter(::projectsFilter).forEach { bom.evaluationDependsOn(it.path) }

dependencies {
constraints {
rootProject.subprojects.filter { project ->
// Only declare dependencies on projects that will have publications
projectsFilter(project) && project.tasks.findByName("publish")?.enabled == true
}.forEach { project ->
project.publishing.publications.forEach { publication: Publication ->
if (publication is MavenPublication) {
// use publication coordinates rather than project because they could differ
api("${publication.groupId}:${publication.artifactId}:${publication.version}")
}
}
}
}
}

/**
* For additional modules, we use a combination of rootProject and subproject names for artifact name and similar things,
* i.e. kotlin-faker-bom
*/
private val fullName: String = "${rootProject.name}-${project.name}"

publishing {
publications {
create<MavenPublication>("FakerBom") {
from(components["javaPlatform"])
groupId = project.group.toString()
artifactId = fullName
version = project.version.toString()
pom {
packaging = "pom"
name.set("kotlin-faker")
description.set("Generate realistically looking fake data such as names, addresses, banking details, and many more, that can be used for testing and data anonymization purposes.")
url.set("https://github.com/serpro69/kotlin-faker")
scm {
connection.set("scm:git:https://github.com/serpro69/kotlin-faker")
developerConnection.set("scm:git:https://github.com/serpro69")
url.set("https://github.com/serpro69/kotlin-faker")
}
issueManagement {
url.set("https://github.com/serpro69/kotlin-faker/issues")
}
licenses {
license {
name.set("MIT")
url.set("https://opensource.org/licenses/mit-license.php")
}
}
developers {
developer {
id.set("serpro69")
name.set("Serhii Prodan")
}
}
}
}
}
}

signing {
sign(publishing.publications["FakerBom"])
}

tasks.withType<PublishToMavenRepository>().configureEach {
dependsOn(project.tasks.getByName("tag"))
dependsOn(tasks.withType(Sign::class.java))
onlyIf("Not snapshot") { !isSnapshot.get() }
onlyIf("New tag") { newTag.get() }
}

tasks.withType<PublishToMavenLocal>().configureEach {
onlyIf("In development") { isSnapshot.get() }
}

tasks.withType<Sign>().configureEach {
dependsOn(project.tasks.getByName("tag"))
onlyIf("Not snapshot") { !isSnapshot.get() }
onlyIf("New tag") { newTag.get() }
}
Loading