Skip to content

Commit 7757e9d

Browse files
authored
document how to use the BOM (#1198)
* document how to use the BOM Signed-off-by: Gregor Zeitlinger <[email protected]> * set latest release Signed-off-by: Gregor Zeitlinger <[email protected]> * set latest release Signed-off-by: Gregor Zeitlinger <[email protected]> --------- Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent d21b6c3 commit 7757e9d

File tree

3 files changed

+102
-7
lines changed

3 files changed

+102
-7
lines changed

.github/workflows/github-pages.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ jobs:
3434
HUGO_VERSION: 0.115.4
3535
steps:
3636
- uses: actions/checkout@v4
37+
with:
38+
fetch-tags: 'true'
3739
- name: Set up JDK
3840
uses: actions/setup-java@v4
3941
with:
4042
java-version: 17
4143
distribution: temurin
4244
cache: 'maven'
45+
- name: Set release version
46+
run: ./scripts/set-release-version-github-pages.sh
4347
- name: Install Hugo CLI
4448
run: |
4549
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \

docs/content/getting-started/quickstart.md

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Quickstart
3-
weight: 1
3+
weight: 0
44
---
55

66
This tutorial shows the quickest way to get started with the Prometheus Java metrics library.
@@ -15,34 +15,118 @@ We use the following dependencies:
1515
{{< tabs "uniqueid" >}}
1616
{{< tab "Gradle" >}}
1717
```
18-
implementation 'io.prometheus:prometheus-metrics-core:1.0.0'
19-
implementation 'io.prometheus:prometheus-metrics-instrumentation-jvm:1.0.0'
20-
implementation 'io.prometheus:prometheus-metrics-exporter-httpserver:1.0.0'
18+
implementation 'io.prometheus:prometheus-metrics-core:$version'
19+
implementation 'io.prometheus:prometheus-metrics-instrumentation-jvm:$version'
20+
implementation 'io.prometheus:prometheus-metrics-exporter-httpserver:$version'
2121
```
2222
{{< /tab >}}
2323
{{< tab "Maven" >}}
2424
```xml
2525
<dependency>
2626
<groupId>io.prometheus</groupId>
2727
<artifactId>prometheus-metrics-core</artifactId>
28-
<version>1.0.0</version>
28+
<version>$version</version>
2929
</dependency>
3030
<dependency>
3131
<groupId>io.prometheus</groupId>
3232
<artifactId>prometheus-metrics-instrumentation-jvm</artifactId>
33-
<version>1.0.0</version>
33+
<version>$version</version>
3434
</dependency>
3535
<dependency>
3636
<groupId>io.prometheus</groupId>
3737
<artifactId>prometheus-metrics-exporter-httpserver</artifactId>
38-
<version>1.0.0</version>
38+
<version>$version</version>
3939
</dependency>
4040
```
4141
{{< /tab >}}
4242
{{< /tabs >}}
4343

4444
There are alternative exporters as well, for example if you are using a Servlet container like Tomcat or Undertow you might want to use `prometheus-exporter-servlet-jakarta` rather than a standalone HTTP server.
4545

46+
# Dependency management
47+
48+
A Bill of Material
49+
([BOM](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms))
50+
ensures that versions of dependencies (including transitive ones) are aligned.
51+
This is especially important when using Spring Boot, which manages some of the dependencies of the project.
52+
53+
You should omit the version number of the dependencies in your build file if you are using a BOM.
54+
55+
{{< tabs "uniqueid" >}}
56+
{{< tab "Gradle" >}}
57+
58+
You have two ways to import a BOM.
59+
60+
First, you can use the Gradle’s native BOM support by adding `dependencies`:
61+
62+
```kotlin
63+
import org.springframework.boot.gradle.plugin.SpringBootPlugin
64+
65+
plugins {
66+
id("java")
67+
id("org.springframework.boot") version "3.2.O" // if you are using Spring Boot
68+
}
69+
70+
dependencies {
71+
implementation(platform(SpringBootPlugin.BOM_COORDINATES)) // if you are using Spring Boot
72+
implementation(platform("io.prometheus:prometheus-metrics-bom:$version"))
73+
}
74+
```
75+
76+
The other way with Gradle is to use `dependencyManagement`:
77+
78+
```kotlin
79+
plugins {
80+
id("java")
81+
id("org.springframework.boot") version "3.2.O" // if you are using Spring Boot
82+
id("io.spring.dependency-management") version "1.1.0" // if you are using Spring Boot
83+
}
84+
85+
dependencyManagement {
86+
imports {
87+
mavenBom("io.prometheus:prometheus-metrics-bom:$version")
88+
}
89+
}
90+
```
91+
92+
{{% alert title="Note" color="info" %}}
93+
94+
Be careful not to mix up the different ways of configuring things with Gradle.
95+
For example, don't use
96+
`implementation(platform("io.prometheus:prometheus-metrics-bom:$version"))`
97+
with the `io.spring.dependency-management` plugin.
98+
99+
{{% /alert %}}
100+
101+
{{< /tab >}}
102+
{{< tab "Maven" >}}
103+
104+
{{% alert title="Note" color="info" %}}
105+
106+
Import the Prometheus Java metrics BOMs before any other BOMs in your
107+
project. For example, if you import the `spring-boot-dependencies` BOM, you have
108+
to declare it after the Prometheus Java metrics BOMs.
109+
110+
{{% /alert %}}
111+
112+
The following example shows how to import the Prometheus Java metrics BOMs using Maven:
113+
114+
```xml
115+
<dependencyManagement>
116+
<dependencies>
117+
<dependency>
118+
<groupId>io.prometheus</groupId>
119+
<artifactId>prometheus-metrics-bom</artifactId>
120+
<version>$version</version>
121+
<type>pom</type>
122+
<scope>import</scope>
123+
</dependency>
124+
</dependencies>
125+
</dependencyManagement>
126+
```
127+
128+
{{< /tab >}}
129+
{{< /tabs >}}
46130

47131
# Example Application
48132

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
version=$(git tag -l | grep 'v' | sort | tail -1 | sed 's/v//')
6+
marker="\$version"
7+
sed -i "s/$marker/$version/g" docs/content/getting-started/quickstart.md

0 commit comments

Comments
 (0)