<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>org.neo4j.driver</groupId>
    <artifactId>neo4j-java-driver-parent</artifactId>
    <version>4.4.3</version>
    <relativePath>..</relativePath>
  </parent>

  <artifactId>neo4j-java-driver</artifactId>

  <packaging>jar</packaging>
  <name>Neo4j Java Driver</name>
  <description>Access to the Neo4j graph database through Java</description>

  <properties>
    <moduleName>org.neo4j.driver</moduleName>
    <rootDir>${project.basedir}/..</rootDir>
    <maven.deploy.skip>false</maven.deploy.skip>
  </properties>

  <dependencies>
    <!-- The original driver that will be repackaged. -->
    <dependency>
      <groupId>org.neo4j.driver</groupId>
      <artifactId>neo4j-java-driver-slim</artifactId>
      <version>${project.version}</version>
      <optional>true</optional>
    </dependency>

    <!-- Optional and / or provided dependencies, as they are not transitive to the original driver they must be declared again. -->
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.graalvm.nativeimage</groupId>
      <artifactId>svm</artifactId>
    </dependency>

    <!-- As we pretend the driver being provided only, we need be explicit about the one dependency we actually didn't shade. -->
    <dependency>
      <groupId>org.reactivestreams</groupId>
      <artifactId>reactive-streams</artifactId>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <!-- Extract the original sources again -->
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-appCtx</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/generated-sources/slim</outputDirectory>
              <overwrite>true</overwrite>
              <resources>
                <resource>
                  <directory>${rootDir}/driver/src/main/java</directory>
                  <includes>**\/*.java</includes>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <!-- Attach them -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-original-sources</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${project.build.directory}/generated-sources/slim</source>
              </sources>
            </configuration>
          </execution>
          <execution>
            <id>set-osgi-version</id>
            <phase>validate</phase>
            <goals>
              <goal>parse-version</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>test-jar</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <archive>
            <index>true</index>
            <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
            <manifest>
              <packageName>org/neo4j/driver</packageName>
            </manifest>
            <manifestEntries>
              <!-- This is used to programmatically determine the driver version -->
              <Implementation-Version>${project.version}-${build.revision}</Implementation-Version>
              <!-- Stable module name for JDK9 automatic modules -->
              <Automatic-Module-Name>${moduleName}</Automatic-Module-Name>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <artifactSet>
                <includes>
                  <include>io.netty:*</include>
                  <include>io.projectreactor:*</include>
                </includes>
              </artifactSet>
              <relocations>
                <relocation>
                  <pattern>io.netty</pattern>
                  <shadedPattern>org.neo4j.driver.internal.shaded.io.netty</shadedPattern>
                </relocation>
                <relocation>
                  <pattern>reactor</pattern>
                  <shadedPattern>org.neo4j.driver.internal.shaded.reactor</shadedPattern>
                </relocation>
              </relocations>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
              </transformers>
              <filters>
                <filter>
                  <artifact>io.netty:*</artifact>
                  <excludes>
                    <exclude>META-INF/native-image/**</exclude>
                  </excludes>
                </filter>
              </filters>
              <shadeTestJar>true</shadeTestJar>
              <createSourcesJar>true</createSourcesJar>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>
