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 an option to not automatically add BOM #701

Merged
merged 2 commits into from
Apr 24, 2023
Merged

Conversation

melix
Copy link
Collaborator

@melix melix commented Apr 24, 2023

This option has (at least) a couple use cases:

  1. the issue described in Make it possible to allow users to define the Micronaut BOM (in order to achieve centralized version management) #681, when a user wants to drive the Micronaut version from a catalog, or directly in their dependencies (although this is probably redundant with Add a plugin to import the Micronaut Platform catalog #694)

  2. we use the Gradle plugins in our module builds, where it's going to look for the platform BOM, which is not necessarily what we want, since we want to use local versions of projects and possibly override transitive versions

Closes #681

This option has (at least) a couple use cases:

1. the issue described in #681, when a user wants to drive the
Micronaut version from a catalog, or directly in their dependencies
(although this is probably redundant with #694)

2. we use the Gradle plugins in our module builds, where it's going
to look for the platform BOM, which is not necessarily what we
want, since we want to use local versions of projects and possibly
override transitive versions

Closes #681
@melix melix added the type: improvement A minor improvement to an existing feature label Apr 24, 2023
@melix melix added this to the 4.0.0 milestone Apr 24, 2023
@melix melix self-assigned this Apr 24, 2023
@melix
Copy link
Collaborator Author

melix commented Apr 24, 2023

Here's an example of how a Micronaut module build can be adapted to use this flag, on micronaut-rabbitmq:

diff --git a/buildSrc/src/main/groovy/io.micronaut.build.internal.rabbitmq-examples.gradle b/buildSrc/src/main/groovy/io.micronaut.build.internal.rabbitmq-examples.gradle
index d632e272..97e7fcfe 100644
--- a/buildSrc/src/main/groovy/io.micronaut.build.internal.rabbitmq-examples.gradle
+++ b/buildSrc/src/main/groovy/io.micronaut.build.internal.rabbitmq-examples.gradle
@@ -5,6 +5,9 @@ plugins {
 }
 
 dependencies {
+    micronautBoms(platform(mn.micronaut.core.bom))
+    micronautBoms(platform(mnTest.micronaut.test.bom))
+    micronautBoms(platform(mnTestResources.micronaut.test.resources.bom))
     testImplementation projects.micronautRabbitmq
     testImplementation mn.reactor
     testImplementation mnSerde.micronaut.serde.support
@@ -18,7 +21,8 @@ configurations.all {
     }
 }
 micronaut {
-    version libs.versions.micronaut.platform.get()
+    importMicronautPlatform = false
+    //version libs.versions.micronaut.platform.get()
     testRuntime "junit5"
     testResources {
         clientTimeout = 300
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index b421ff91..cd10d545 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -1,8 +1,9 @@
 [versions]
 micronaut-docs = '2.0.0'
 micronaut = '4.0.0-M2'
-micronaut-platform = '4.0.0-M1'
+#micronaut-platform = '4.0.0-M1'
 micronaut-test = '4.0.0-M1'
+micronaut-test-resources = '2.0.0-M1'
 micronaut-gradle-plugin = "4.0.0-M1"
 groovy = '4.0.10'
 spock = '2.3-groovy-4.0'
@@ -36,6 +37,7 @@ testcontainers-spock = { module = 'org.testcontainers:spock', version.ref = 'tes
 
 micronaut-micrometer = { module = "io.micronaut.micrometer:micronaut-micrometer-bom", version.ref = "micronaut-micrometer" }
 micronaut-serde = { module = "io.micronaut.serde:micronaut-serde-bom", version.ref = "micronaut-serde" }
+micronaut-test-resources = { module = "io.micronaut.testresources:micronaut-test-resources-bom", version.ref = "micronaut-test-resources" }
 gradle-micronaut = { module = "io.micronaut.gradle:micronaut-gradle-plugin", version.ref = "micronaut-gradle-plugin" }
 gradle-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
 gradle-kotlin-allopen = { module = "org.jetbrains.kotlin:kotlin-allopen", version.ref = "kotlin" }
diff --git a/settings.gradle b/settings.gradle
index 4dbb2206..881afc18 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -26,4 +26,5 @@ micronautBuild {
     importMicronautCatalog()
     importMicronautCatalog("micronaut-micrometer")
     importMicronautCatalog("micronaut-serde")
+    importMicronautCatalog("micronaut-test-resources")
 }

Basically, the micronaut.platform solution has the advantage of being easy to setup, but you would still possibly add constraints which are not wanted when testing. By setting importMicronautPlatform to false, then the BOM is not applied anymore, so you have to explicitly import all the module BOMs that you are using, which provides correctness at the cost of simplicity.

@sonarcloud
Copy link

sonarcloud bot commented Apr 24, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

88.2% 88.2% Coverage
0.0% 0.0% Duplication

@melix melix merged commit a8c32f0 into master Apr 24, 2023
@melix melix deleted the cc/micronaut-boms-flag branch April 24, 2023 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: improvement A minor improvement to an existing feature
Projects
None yet
2 participants