Include the SDK in Your Project

Applications that run in the HERE Workspace may have dependencies on the following components:

  • HERE Data SDK for Java & Scala libraries, such as the Location Library, the Data Processing Library, or the Data Client Library

  • Libraries provided as part of a runtime environment. The Workspace supports two runtime environments: batch and stream. The batch environment provides a minimal amount of libraries that Apache Spark applications use. The stream environment provides libraries that the Apache Flink applications use.

  • Protobuf schemas for encoding and decoding data, like schemas for HERE Map Content, HERE Weather or user provided ones

For all mentioned types of dependencies, the HERE Data SDK provides different ways for managing these dependencies.

HERE Data SDK Libraries

The libraries within the Data SDK have different versions. For example, Data Processing Library 3.1.13 and Data Client Library 0.2.24 are part of the same Data SDK release. Also, there are interdependencies within the Data SDK, for example the Location Library and the Data Processing Library depend on the Data Client Library, which you must take into account when managing dependencies.

To help with the dependency management, the Data SDK provides Bill Of Materials (BOMs) files. Each BOM is a Maven POM file that lists compatible versions of these libraries.

There are three different BOM files:

  • sdk-batch-bom.pom - The file contains compatible versions of the HERE Data SDK for Java & Scala libraries, their dependencies and the libraries provided by the HERE Workspace Batch 2.1.0 runtime environment (Apache Spark 2.4). See SDK Libraries for Batch Processing.
  • sdk-stream-bom.pom - The file contains compatible versions of Data SDK libraries, their dependencies and the libraries provided by the HERE Workspace Stream 3.0.0 runtime environment (Apache Flink 1.7). See SDK Libraries for Stream Processing.
  • sdk-standalone-bom.pom - The file contains compatible libraries of Data SDK and their dependencies. Use this POM file for running the application on your own environment. See SDK Libraries for usage in Standalone mode.

Note that you need repository credentials for the dependencies to resolve.

Include BOMs

You can include the BOM files in your project POM file in two different ways:

  1. As parent POM file (recommended):

    <!-- Inherit all properties, dependency management and plugin management from the SDK -->
    <parent>
    <groupId>com.here.platform</groupId>
    <artifactId>sdk-batch-bom</artifactId>
    <version>2.19.10</version>
    </parent>
    
  2. Or, if your project already has a parent, as import dependency:

    <dependencyManagement>
    <dependencies>
     <dependency>
        <!-- Import dependency management from the SDK, but properties and plugin management are skipped -->
        <groupId>com.here.platform</groupId>
        <artifactId>sdk-batch-bom</artifactId>
        <version>2.19.10</version>
        <type>pom</type>
        <scope>import</scope>
     </dependency>
    </dependencies>
    </dependencyManagement>
    

Note: Examples

All code snippets use sdk-batch-bom as an example, but the same instructions are applicable to sdk-stream-bom and sdk-standalone-bom. Be aware that only one SDK BOM file should be used in a project.

We recommend to include the BOM files as parent because the files contain a plugin management section and useful properties.

For example, the plugin management section of sdk-batch-bom and sdk-stream-bom contains the platform profile to create a fat JAR. You need to upload this fat JAR to the Workspace before you run the application in the cloud.

Another important part of the plugin management section and platform profile is maven-shade-plugin that shades protobuf-java 3+. The shading mechanism is required because of a conflict between the version of the protobuf-java library used in Apache Flink and Apache Spark, and the version of this library used by Data SDK libraries and Protobuf layer schemas. The Data SDK uses a newer version 3+, but both stream and batch environments provide protobuf 2+.

You can activate the platform profile as follows: mvn -Pplatform package or mvn --activate-profiles=platform package.

If for some reason you cannot include the files as parent into your POM, check the content of the files and copy properties and plugin management configuration that are relevant for your projects.

Include Dependencies

As soon as your project includes a BOM file, the project can reference a Data SDK library or dependency without specifying the actual version of the library.

<dependencies>
  <!-- Reference to pipeline runner library from Data Processing Library -->
  <dependency>
      <groupId>com.here.platform.data.processing</groupId>
      <artifactId>pipeline-runner-java_2.11</artifactId>
  </dependency>
</dependencies>

The approach simplifies migration from one Data SDK version to a newer one. Changing the version of the sdk-batch-bom updates the versions of all Data SDK libraries and their dependencies, and the versions of the libraries provided by the batch environment.

This approach simplifies the migration from one Data SDK version to a more recent one. If you change the version of the sdk-batch-bom in your project, your project will use updated versions of the following:

  • Data SDK libraries
  • dependencies of all Data SDK libraries
  • libraries provided by the batch environment

Sometimes an application that depends on a different version of a package defined in the BOM may face runtime exceptions such as the following:

  • ClassNotFoundException
  • NoSuchMethodError

These exceptions are raised when classes or methods are not found in the library provided in the runtime environment. There are two common cases:

  1. The runtime environment contains an older version of the library and the application requires a newer one with new methods and classes.
  2. The runtime environment contains a newer version of the library, but the application uses removed deprecated methods or classes from an old version.

If the library is referenced in your project then it can be solved by using a corresponding version of the library from the BOM files. But it can happen that the version of one of the transitive dependencies conflicts with the version provided in the runtime environment. In this case, you need to shade this transitive dependency. For an example of how to shade a library, see the platform profile in sdk-batch-bom or sdk-stream-bom. This profile shades the protobuf-java package as mentioned earlier.

For more information about how to import dependencies and BOMs, see the Maven Dependency Management Guide.

Note: Archetypes

The Workspace-provided batch and streaming archetypes contain BOMs and have the necessary dependencies in their project POM files. Only the Maven build system supports these archetypes.

Pipelines Runtime Environment Libraries

The HERE Workspace provides batch and streaming pipelines to run location data-based applications. Each pipeline job is executed within a specific runtime environment. This environment consists of the following:

  1. Java Runtime Environment (JRE)
  2. Apache Spark or Apache Flink framework

A batch (Spark) or streaming (Flink) environment comes with a list of packages that are loaded by the Java Virtual Machine (JVM) and take precedence over any other application-provided package.

To describe the list of packages that are part of the runtime environment, the Data SDK provides two environment BOMs:

  • environment-batch-2.1.0.pom
  • environment-stream-3.0.0.pom

Packages for a runtime environment are marked as provided in the corresponding environment BOM. For example, the Apache Spark package spark-core is marked as provided in environment-batch-2.1.0.pom:

<dependency>
  <groupId>org.apache.spark</groupId>
  <artifactId>spark-core_${scala.compat.version}</artifactId>
  <version>${spark.version}</version>
  <scope>provided</scope>
</dependency>

Note that sdk-batch-bom and sdk-stream-bom files include the corresponding environment-batch-2.1.0.pom and environment-stream-3.0.0.pom files. A project that uses sdk-batch-bom or sdk-stream-bom doesn't need to explicitly include the corresponding environment POM file. For more information about the libraries provided by the pipeline runtime environments, see the corresponding environment POM files.

Protobuf Schemas

The HERE Workspace allows users to define their Protobuf schemas and distribute them in the Workspace. The schemas are stored in a special repository that requires platform credentials. You can access this repository only by means of the HERE Maven Wagon in Maven projects. For SBT projects, you can use the unofficial HERE SBT Resolver plugin.

Follow the instructions to install the Maven Wagon plugin or SBT Resolver plugin in README.md on GitHub.

If you have one of the plugins configured, then, to include a schema artifact shared with you in your project, follow the steps below.

  1. Go to the HERE portal.
  2. Find a shared schema you want to include and open Artifacts tab.
  3. For Maven projects, copy instructions and paste them in your project. For SBT projects, convert the instructions in SBT format like the following code and add them to build.sbt file:
libraryDependencies += "groupId" % "artifactId" % "version"

For more information, see Create and Extend Schemas.

results matching ""

    No results matching ""