11---
22title : Quickstart
3- weight : 1
3+ weight : 0
44---
55
66This 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
4444There 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
0 commit comments