Solve dependency issues

There are multiple ways to include neo4j artifacts. In this article, we will focus on maven based on different scenarios or errors. The most common issue is setting up the dependencies properly in pom.xml.

Verify that you have the right dependencies

You can execute the following maven command in the folder where you have the pom.xml :

# resolve dependency in the local repository (by default in ~/.m2/)
mvn dependency:resolve

# displays the dependencies as a tree
mvn dependency:tree

#purge local repo and resolve dependencies
mvn dependency:purge-local-repository

# perform integration tests
mvn verify

In version 3.5, only 3 artifacts are required even if you are running unit tests:

For Enterprise, your pom.xml should contains:

pom.xml
<properties>
	<neo4j.version>3.5.6</neo4j.version>
</properties>

<dependencies>
		<dependency>
			<groupId>com.neo4j</groupId>
			<artifactId>neo4j-enterprise</artifactId>
			<version>${neo4j.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.neo4j.driver</groupId>
			<artifactId>neo4j-java-driver</artifactId>
			<version>${neo4j-java-driver.version}</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.neo4j.test</groupId>
			<artifactId>neo4j-harness-enterprise</artifactId>
			<version>${neo4j.version}</version>
			<scope>test</scope>
		</dependency>
 <dependencies>

For Community Edition, your pom.xml should contains:

pom.xml
 <properties>
	<neo4j.version>3.5.6</neo4j.version>
</properties>
 <dependencies>
		<dependency>
			<groupId>org.neo4j</groupId>
			<artifactId>neo4j</artifactId>
			<version>${neo4j.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.neo4j.driver</groupId>
			<artifactId>neo4j-java-driver</artifactId>
			<version>${neo4j-java-driver.version}</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.neo4j.test</groupId>
			<artifactId>neo4j-harness-enterprise</artifactId>
			<version>${neo4j.version}</version>
			<scope>test</scope>
		</dependency>
 <dependencies>

Resolving dependencies using a private sonatype nexus configured as a mirror repository

This is the preferred approach. It allows you to stay up to date and automatically fetch the updates. To do that, you need to login into nexus as an admin or reach out to your nexus adminstrator and ensure that the repositories are available and healthy.

  • For community edition, you need to add one repository:

org.neo4j:neo4j, the public maven repo url is https://repo.maven.apache.org/maven2/

  • For enterprise, you need to add the two below repositories:

com.neo4j:neo4j-enterprise (see ‘KB Dependency location for Neo4j Enterprise Edition artifacts’ for url/username/password)

org.neo4j:neo4j (available on public repo https://repo.maven.apache.org/maven2/)

The naming convention is groupId:artifactId. For example: org.neo4j:neo4j is actually groupid=org.neo4j AND artifactId=neo4j

Resolving dependencies using a private sonatype nexus configured as a hosted repository

Warning
This approach is not recommended since it is manual and prone to error. It should be used as a last resort solution.

Please keep in mind that neo4j requires more than 70-200 artifacts depending on the version and the scope used.

  • The easiest way to implement this is to compress the .m2/repository folder once you have downloaded all the dependencies
  • You will need to upload BOTH the jar and the associated pom file into your repository.
  • Execute the following maven the command and compare it on a machine that has access to the official repositories
mvn dependency:tree

If something you spot differences, browse your nexus repository with a web browser and check the signature of the .pom file.

Resolving dependencies using a local folder (Internet required)

This is the easiest approach but you will enventually have to repeat those steps to upgrade to the latest maintenance release.

  • Open a terminal and go into the project folder that contains the pom.xml
  • Use the following mvn command to download jars from a source machine that has access to internet. It will copy them into a local folder
mvn dependency:go-offline -Dmaven.repo.local=./remoterepo

(You can request support to do it if your internet is restricted)

  • Zip the folder on the source
  • Extract it on the target machine
  • Specify the following in your pom.xml
pom.xml
    <repositories>
        <repository>
            <id>neo4j</id>
            <url>file://</url>
            <!-- ie <url>file:///home/neo4j/maven/remoterepo</url> -->
        </repository>
        <repository>
            <id>neo4j-enterprise</id>
            <url>file://</url>
            <!-- ie <url>file:///home/neo4j/maven/remoterepoenterprise</url> -->
        </repository>
    </repositories>

  • Last Modified: 2020-08-03 16:12:21 UTC by Jérémie Phoulchand.
  • Relevant for Neo4j Versions: 3.5,3.4.
  • Relevant keywords maven, java, embedded, user-defined-procedures, dependencies, upgrade.