<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright 2015-2019 The OpenZipkin Authors

    Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
    in compliance with the License. You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License
    is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
    or implied. See the License for the specific language governing permissions and limitations under
    the License.

-->
<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>

  <parent>
    <groupId>io.zipkin</groupId>
    <artifactId>zipkin-parent</artifactId>
    <version>2.16.0</version>
  </parent>

  <groupId>io.zipkin.zipkin2</groupId>
  <artifactId>zipkin</artifactId>
  <name>Zipkin Core Library</name>

  <properties>
    <main.basedir>${project.basedir}/..</main.basedir>
    <main.java.version>1.6</main.java.version>
    <main.signature.artifact>java16</main.signature.artifact>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.jvnet</groupId>
      <artifactId>animal-sniffer-annotation</artifactId>
      <version>1.0</version>
      <!-- annotations are not runtime retention, so don't need a runtime dep -->
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <!-- this dependency is shaded out -->
      <optional>true</optional>
    </dependency>

    <!-- to mock Platform calls -->
    <dependency>
      <groupId>org.powermock</groupId>
      <artifactId>powermock-module-junit4</artifactId>
      <version>${powermock.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.powermock</groupId>
      <artifactId>powermock-api-mockito2</artifactId>
      <version>${powermock.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.esotericsoftware.kryo</groupId>
      <artifactId>kryo</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <!-- Need to block import of shaded packages in bnd.bnd as maven bundle plugin analyzes the unshaded jar -->
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <configuration>
          <instructions>
            <_include>-bnd.bnd</_include>
          </instructions>
        </configuration>
      </plugin>
      <!-- Rewrites bytecode back down to java 1.6 -->
      <plugin>
        <groupId>net.orfjackal.retrolambda</groupId>
        <artifactId>retrolambda-maven-plugin</artifactId>
        <version>2.5.6</version>
        <executions>
          <execution>
            <goals>
              <goal>process-main</goal>
            </goals>
            <configuration>
              <target>${main.java.version}</target>
              <fork>true</fork>
              <quiet>true</quiet>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <!-- Use of gson is internal only -->
      <plugin>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <createDependencyReducedPom>false</createDependencyReducedPom>
              <minimizeJar>true</minimizeJar>
              <filters>
                <filter>
                  <artifact>com.google.code.gson:gson</artifact>
                  <includes>
                    <include>com/google/gson/stream/JsonReader*.class</include>
                    <include>com/google/gson/stream/JsonToken.class</include>
                    <include>com/google/gson/stream/MalformedJsonException.class</include>
                    <include>com/google/gson/internal/JsonReaderInternalAccess.class</include>
                  </includes>
                </filter>
              </filters>
              <relocations>
                <relocation>
                  <pattern>com.google.gson</pattern>
                  <shadedPattern>zipkin2.internal.gson</shadedPattern>
                </relocation>
              </relocations>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <manifestEntries>
                    <Automatic-Module-Name>zipkin2</Automatic-Module-Name>
                  </manifestEntries>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <id>default-jar</id>
            <configuration>
              <archive>
                <!-- prevents huge pom file from also being added to the jar under META-INF/maven -->
                <addMavenDescriptor>false</addMavenDescriptor>
                <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
              </archive>
            </configuration>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
