Building Spring Data Neo4j
-
SDN_NEO4J_VERSION
:指定 Neo4j Docker 映像版本。 -
SDN_NEO4J_ACCEPT_COMMERCIAL_EDITION
:接受 Neo4j 企业版的许可协议。 -
SDN_NEO4J_URL
:连接到本地运行的 Neo4j 实例。 -
SDN_NEO4J_PASSWORD
:本地 Neo4j 实例的 neo4j 用户密码。
指南详细介绍了不同环境变量的用途,以及如何使用它们在本地或使用 Docker 构建 Spring Data Neo4j 项目。它还提供了有关 Neo4j 安装、Checkstyle 规则和质量门的信息。
Requirements
-
JDK 17+ (Can be OpenJDK or Oracle JDK)
-
Maven 3.8.5 (We provide the Maven wrapper, see
mvnw
respectivelymvnw.cmd
in the project root; the wrapper downloads the appropriate Maven version automatically) -
A Neo4j 5.+ database, either
-
running locally
-
or indirectly via Testcontainers and Docker
-
Running the build
以下部分是备选方案,大致按工作量升序排列。
The following sections are alternatives and roughly sorted by increased effort.
所有构建都需要项目的本地副本:
All builds require a local copy of the project:
$ git clone git@github.com:spring-projects/spring-data-neo4j.git
在继续之前,请验证您本地安装的 JDK 版本。输出应类似于:
Before you proceed, verify your locally installed JDK version. The output should be similar:
$ java -version
java version "18.0.1" 2022-04-19
Java(TM) SE Runtime Environment (build 18.0.1+10-24)
Java HotSpot(TM) 64-Bit Server VM (build 18.0.1+10-24, mixed mode, sharing)
With Docker installed
Using the default image
如果您尚未安装 Docker,请前往 Docker Desktop。简而言之,Docker 是一个帮助您在所谓的容器中使用 OS 级虚拟化运行轻量级软件映像的工具。
If you don’t have Docker installed, head over to Docker Desktop. In short, Docker is a tool that helps you running lightweight software images using OS-level virtualization in so-called containers.
我们的构建使用 Testcontainers Neo4j 来启动数据库实例。
Our build uses Testcontainers Neo4j to bring up a database instance.
$ ./mvnw clean verify
在 Windows 计算机上,使用
On a Windows machine, use
$ mvnw.cmd clean verify
输出应类似于:
The output should be similar.
Using another image
要使用的映像版本可以通过环境变量进行配置,如下所示:
The image version to use can be configured through an environmental variable like this:
$ SDN_NEO4J_VERSION=5.3.0-enterprise SDN_NEO4J_ACCEPT_COMMERCIAL_EDITION=yes ./mvnw clean verify
这里我们使用 5.3.0 企业版,还接受许可协议。
Here we are using 5.3.0 enterprise and also accept the license agreement.
如果您无法内联指定环境变量,请查阅您的操作系统或 shell 手册,了解如何定义环境变量。
Consult your operating system or shell manual on how to define environment variables if specifying them inline does not work for you.
Against a locally running database
对本地运行的数据库 will 运行会抹除其全部内容。
Running against a locally running database will erase its complete content.
相对于每次重新启动容器,针对本地运行的数据库进行构建速度更快。我们在开发过程中经常这样做。
Building against a locally running database is faster, as it does not restart a container each time. We do this a lot during our development.
您可以在我们的 download center 处免费获取 Neo4j 副本。
You can get a copy of Neo4j at our download center free of charge.
请下载适用于您操作系统的版本,然后按照说明启动它。一个必需的步骤是,在您启动数据库后打开一个浏览器,并转到 [role="bare"][role="bare"]http://localhost:7474 ,然后将默认密码从 neo4j
更改为您喜欢的密码。
Please download the version applicable to your operating system and follow the instructions to start it.
A required step is to open a browser and go to [role="bare"]http://localhost:7474 after you started the database and change the default password from neo4j
to something of your liking.
在此之后,您可以通过指定本地 bolt
URL 来运行完整构建:
After that, you can run a complete build by specifying the local bolt
URL:
$ SDN_NEO4J_URL=bolt://localhost:7687 SDN_NEO4J_PASSWORD=verysecret ./mvnw clean verify
Summary of environment variables controlling the build
Name | Default value | Meaning |
---|---|---|
|
5.3.0 |
Version of the Neo4j docker image to use, see Neo4j Docker Official Images |
|
no |
Some tests may require the enterprise edition of Neo4j. We build and test against the enterprise edition internally, but we won’t force you to accept the license if you don’t want to. |
|
not set |
Setting this environment allows connecting to a locally running Neo4j instance. We use this a lot during development. |
|
not set |
Password for the |
您需要同时设置 |
You need to set both |
Checkstyle and friends
目前没有质量门来确保代码/测试比率保持原样,但请考虑将测试添加到您的贡献中。
There is no quality gate in place at the moment to ensure that the code/test ratio stays as is, but please consider adding tests to your contributions.
我们有一些相当温和的 Checkstyle 规则,强制执行更多或更少的默认 Java 格式化规则。您将在格式错误或未使用的导入等问题上终止构建。
We have some rather mild checkstyle rules in place, enforcing more or less default Java formatting rules. Your build will break on formatting errors or something like unused imports.