<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>io.last9</groupId>
    <artifactId>vertx-otel-autoconfigure</artifactId>
    <version>2.2.1</version>
    <packaging>pom</packaging>

    <name>Vert.x OpenTelemetry Auto-Configure</name>
    <description>
        Zero-code OpenTelemetry auto-instrumentation for Vert.x applications.
        Supports Vert.x 4 + RxJava 3 and Vert.x 3 + RxJava 2.
    </description>
    <url>https://github.com/last9/vertx-opentelemetry</url>

    <licenses>
        <license>
            <name>MIT License</name>
            <url>https://opensource.org/licenses/MIT</url>
        </license>
    </licenses>

    <developers>
        <developer>
            <name>Last9</name>
            <email>support@last9.io</email>
            <organization>Last9</organization>
            <organizationUrl>https://last9.io</organizationUrl>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:git://github.com/last9/vertx-opentelemetry.git</connection>
        <developerConnection>scm:git:ssh://github.com:last9/vertx-opentelemetry.git</developerConnection>
        <url>https://github.com/last9/vertx-opentelemetry</url>
    </scm>

    <modules>
        <module>vertx-otel-core</module>
        <module>vertx4-rxjava3-otel-autoconfigure</module>
        <module>vertx3-rxjava2-otel-autoconfigure</module>
        <module>vertx3-otel-agent</module>
    </modules>

    <properties>
        <java.version>11</java.version>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <!-- OpenTelemetry — SDK + instrumentation versions must be aligned.
             opentelemetry-instrumentation-bom:2.4.0 was built against SDK 1.38.0;
             mixing SDK 1.35.0 with instrumentation 2.4.0 causes AbstractMethodError
             because HttpSenderProvider interface changed between 1.35.0 and 1.38.0. -->
        <opentelemetry.version>1.38.0</opentelemetry.version>
        <opentelemetry-instrumentation.version>2.4.0</opentelemetry-instrumentation.version>
        <opentelemetry-semconv.version>1.25.0-alpha</opentelemetry-semconv.version>
        <!-- OTel contrib resource detectors (AWS, GCP) — version must align with SDK 1.38.0.
             Contrib follows SDK versioning minus 2 minor versions: 38-2 = 36. -->
        <opentelemetry-contrib.version>1.36.0-alpha</opentelemetry-contrib.version>

        <!-- Vert.x -->
        <vertx4.version>4.5.10</vertx4.version>
        <vertx3.version>3.9.16</vertx3.version>

        <!-- Logging -->
        <slf4j.version>2.0.12</slf4j.version>
        <logback.version>1.5.3</logback.version>

        <!-- Aerospike -->
        <aerospike-client.version>7.2.1</aerospike-client.version>

        <!-- ByteBuddy (Vert.x 3 bytecode instrumentation) -->
        <bytebuddy.version>1.14.18</bytebuddy.version>

        <!-- Test -->
        <junit.version>5.10.1</junit.version>
        <assertj.version>3.27.7</assertj.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- OpenTelemetry BOM -->
            <dependency>
                <groupId>io.opentelemetry</groupId>
                <artifactId>opentelemetry-bom</artifactId>
                <version>${opentelemetry.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!-- OpenTelemetry Instrumentation BOM -->
            <dependency>
                <groupId>io.opentelemetry.instrumentation</groupId>
                <artifactId>opentelemetry-instrumentation-bom</artifactId>
                <version>${opentelemetry-instrumentation.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!-- OpenTelemetry Semantic Conventions -->
            <dependency>
                <groupId>io.opentelemetry.semconv</groupId>
                <artifactId>opentelemetry-semconv</artifactId>
                <version>${opentelemetry-semconv.version}</version>
            </dependency>

            <!-- Core module -->
            <dependency>
                <groupId>io.last9</groupId>
                <artifactId>vertx-otel-core</artifactId>
                <version>${project.version}</version>
            </dependency>

            <!-- Logging -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-nop</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>${logback.version}</version>
            </dependency>

            <!-- ByteBuddy -->
            <dependency>
                <groupId>net.bytebuddy</groupId>
                <artifactId>byte-buddy</artifactId>
                <version>${bytebuddy.version}</version>
            </dependency>
            <dependency>
                <groupId>net.bytebuddy</groupId>
                <artifactId>byte-buddy-agent</artifactId>
                <version>${bytebuddy.version}</version>
            </dependency>

            <!-- Test -->
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter</artifactId>
                <version>${junit.version}</version>
            </dependency>
            <dependency>
                <groupId>org.assertj</groupId>
                <artifactId>assertj-core</artifactId>
                <version>${assertj.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <profiles>
        <profile>
            <!-- Activate with: mvn deploy -P release
                 Requires GitHub secrets: GPG_PRIVATE_KEY, GPG_PASSPHRASE, OSSRH_USERNAME, OSSRH_TOKEN -->
            <id>release</id>
            <build>
                <plugins>
                    <!-- Sign all artifacts with GPG — required by Maven Central -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>3.2.4</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                                <configuration>
                                    <!-- Explicitly select the Last9 signing key so GPG does not
                                         fall back to the first key in the keyring. -->
                                    <keyname>F66DE47944D32F14</keyname>
                                    <!-- loopback mode: allows passphrase via env var in CI
                                         without requiring an interactive terminal -->
                                    <gpgArguments>
                                        <arg>--pinentry-mode</arg>
                                        <arg>loopback</arg>
                                    </gpgArguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Sonatype Central Portal publishing plugin (new portal, not legacy OSSRH).
                         Credentials come from the Maven server 'central', which actions/setup-java
                         maps from MAVEN_USERNAME / MAVEN_PASSWORD environment variables.
                         autoPublish=true: skip the manual "Release" click in the UI.
                         waitUntil=published: block the CI job until Central finishes validation. -->
                    <plugin>
                        <groupId>org.sonatype.central</groupId>
                        <artifactId>central-publishing-maven-plugin</artifactId>
                        <version>0.7.0</version>
                        <extensions>true</extensions>
                        <configuration>
                            <publishingServerId>central</publishingServerId>
                            <tokenAuth>true</tokenAuth>
                            <autoPublish>true</autoPublish>
                            <waitUntil>published</waitUntil>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <!-- Sources and Javadoc JARs are required by Maven Central.
             Declared here (not just in pluginManagement) so the executions
             are bound for all child modules. -->
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.4.1</version>
                <configuration>
                    <!-- Plugin 3.4.1 passes all deps via -classpath only.
                         Version 3.5 introduced automatic module-path detection which
                         fails for luaj-jse (transitive via Vert.x 3): it has a class
                         in the unnamed package, making module descriptor derivation
                         impossible on Java 9+. -->
                    <detectOfflineLinks>false</detectOfflineLinks>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <!-- Run before 'package' so Javadoc sees the original unshaded
                             source classes. If this runs at 'package' (the default), the
                             shade plugin has already replaced the JAR with a fat artifact
                             that bundles OTel classes, causing JPMS split-package errors
                             when Javadoc resolves modules. -->
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.12.1</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.3.0</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>3.3.0</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.2.3</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>3.4.1</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>3.5.1</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <!-- Replace the main JAR in-place; no -shaded suffix.
                                     createDependencyReducedPom=true (the default) is intentional:
                                     the shade plugin installs dependency-reduced-pom.xml so that
                                     consumers do NOT see the bundled OTel deps (esp.
                                     opentelemetry-exporter-sender-okhttp) leaking onto their
                                     classpath. Without this, Maven pulls the transitive JAR onto
                                     the consumer's classpath alongside our shaded copy, causing a
                                     "Multiple HttpSenderProvider found" error at startup. -->
                                <shadedArtifactAttached>false</shadedArtifactAttached>
                                <!-- Keep the reduced POM so Maven consumers don't see bundled deps -->
                                <createDependencyReducedPom>true</createDependencyReducedPom>
                                <!-- Bundle vertx-otel-core plus all OTel SDK, exporter,
                                     instrumentation, and semconv artifacts so the JAR is
                                     self-contained. Vert.x, RxJava, Logback, and SLF4J are
                                     kept as provided — the user's app always supplies those. -->
                                <artifactSet>
                                    <includes>
                                        <include>io.last9:vertx-otel-core</include>
                                        <include>io.opentelemetry:*</include>
                                        <include>io.opentelemetry.semconv:*</include>
                                        <include>io.opentelemetry.instrumentation:*</include>
                                        <!-- AWS + GCP cloud resource detectors -->
                                        <include>io.opentelemetry.contrib:opentelemetry-aws-resources</include>
                                        <include>io.opentelemetry.contrib:opentelemetry-gcp-resources</include>
                                        <!-- GCP detector support library (transitive of gcp-resources) -->
                                        <include>com.google.cloud.opentelemetry:detector-resources-support</include>
                                        <!-- OkHttp + Okio: required by opentelemetry-aws-resources
                                             (Ec2Resource calls IMDS via OkHttpClient).
                                             We bundle the okhttp library itself but still exclude
                                             opentelemetry-exporter-sender-okhttp so that
                                             OkHttpHttpSenderProvider is NOT registered as an OTLP
                                             HttpSenderProvider — only JdkHttpSenderProvider is. -->
                                        <include>com.squareup.okhttp3:okhttp</include>
                                        <include>com.squareup.okio:okio</include>
                                        <include>com.squareup.okio:okio-jvm</include>
                                        <!-- OkHttp 4.x is written in Kotlin — runtime required -->
                                        <include>org.jetbrains.kotlin:kotlin-stdlib</include>
                                        <include>org.jetbrains.kotlin:kotlin-stdlib-jdk7</include>
                                        <include>org.jetbrains.kotlin:kotlin-stdlib-jdk8</include>
                                        <!-- ByteBuddy: bytecode instrumentation for Vert.x 3
                                             zero-code tracing (Router, WebClient interception).
                                             Only used in the v3 fat JAR; shade silently skips
                                             artifacts not present in a module's dependency graph. -->
                                        <include>net.bytebuddy:byte-buddy</include>
                                        <include>net.bytebuddy:byte-buddy-agent</include>
                                        <!-- SLF4J API: required for standalone agent mode where
                                             the app classpath isn't available at premain time.
                                             appendToSystemClassLoaderSearch places this after the
                                             app's classpath, so the app's SLF4J takes precedence
                                             when both are present. -->
                                        <include>org.slf4j:slf4j-api</include>
                                        <include>org.slf4j:slf4j-nop</include>
                                        <!-- Vert.x Micrometer integration + Micrometer core.
                                             Bundled so users get internal Vert.x metrics without
                                             adding any extra dependencies.
                                             NOT relocated — MicrometerMetricsOptions type identity
                                             must be visible to Vert.x's setMetricsOptions() check.
                                             v3 module does not depend on these; shade silently skips
                                             artifacts not present in a module's dependency graph. -->
                                        <include>io.vertx:vertx-micrometer-metrics</include>
                                        <include>io.micrometer:micrometer-core</include>
                                        <include>io.micrometer:micrometer-commons</include>
                                    </includes>
                                    <!-- Exclude the OkHttp-based OTel sender: its SPI file would
                                         register OkHttpHttpSenderProvider alongside JdkHttpSenderProvider
                                         causing a "Multiple HttpSenderProvider found" error at startup.
                                         We still bundle okhttp3 itself (above) for the AWS detector. -->
                                    <excludes>
                                        <exclude>io.opentelemetry:opentelemetry-exporter-sender-okhttp</exclude>
                                    </excludes>
                                </artifactSet>
                                <transformers>
                                    <!-- Merge META-INF/services SPI files from all bundled JARs.
                                         Without this, only one ResourceProvider set survives shading
                                         and cloud/K8s detectors registered by contrib JARs are lost. -->
                                    <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                                    <!-- Expose the fat JAR as a -javaagent for operator-based
                                         injection. OtelAgent.premain() initializes the OTel SDK
                                         and (for v3) installs ByteBuddy class transformers. -->
                                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                        <manifestEntries>
                                            <Premain-Class>io.last9.tracing.otel.OtelAgent</Premain-Class>
                                            <Agent-Class>io.last9.tracing.otel.OtelAgent</Agent-Class>
                                            <Can-Redefine-Classes>true</Can-Redefine-Classes>
                                            <Can-Retransform-Classes>true</Can-Retransform-Classes>
                                        </manifestEntries>
                                    </transformer>
                                </transformers>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>
