Building

Basic Compile and Test

Basic Compile and Test

要构建源代码,您需要安装 JDK 17。

To build the source you will need to install JDK 17.

Spring Cloud 在大多数与构建相关的活动中使用 Maven,而且,您应该能够通过克隆您感兴趣的项目并输入以下内容来快速启动:

Spring Cloud uses Maven for most build-related activities, and you should be able to get off the ground quite quickly by cloning the project you are interested in and typing

$ ./mvnw install

您还可以自己安装 Maven(>=3.3.3)并运行 mvn,以代替以下示例中的 ./mvnw。如果您这样做,那么如果您的本地 Maven 设置不包含 Spring 预发布工件的存储库声明,您可能还需要添加 -P spring

You can also install Maven (>=3.3.3) yourself and run the mvn command in place of ./mvnw in the examples below. If you do that you also might need to add -P spring if your local Maven settings do not contain repository declarations for spring pre-release artifacts.

请注意,您可能需要通过设置 MAVEN_OPTS 环境变量(值为 -Xmx512m -XX:MaxPermSize=128m)来增加可用于 Maven 的内存量。我们尝试在 .mvn 配置中涵盖这一点,因此如果您发现必须这样做才能使构建成功,请提交工单以将设置添加到源代码控制中。

Be aware that you might need to increase the amount of memory available to Maven by setting a MAVEN_OPTS environment variable with a value like -Xmx512m -XX:MaxPermSize=128m. We try to cover this in the .mvn configuration, so if you find you have to do it to make a build succeed, please raise a ticket to get the settings added to source control.

通常要求在测试中需要中间件(即 Redis)的项目安装并运行本地实例的 [Docker]([role="bare"][role="bare"]https://www.docker.com/get-started)。

The projects that require middleware (i.e. Redis) for testing generally require that a local instance of [Docker]([role="bare"]https://www.docker.com/get-started) is installed and running.

Documentation

spring-cloud-build 模块有一个“docs”概要文件,如果您启用它,它会尝试使用 Antora 从 modules/ROOT/ 构建 asciidoc 源代码。

The spring-cloud-build module has a "docs" profile, and if you switch that on it will try to build asciidoc sources using Antora from modules/ROOT/.

作为该过程的一部分,它会查找 docs/src/main/asciidoc/README.adoc 并通过加载所有 include 来处理它,但不解析或呈现它,只将其复制到 ${main.basedir}(默认为 ${basedir},即项目的根目录)。如果 README 有任何更改,它将在 Maven 构建之后在正确的位置显示为已修改文件。只提交它并推送更改。

As part of that process it will look for a docs/src/main/asciidoc/README.adoc and process it by loading all the includes, but not parsing or rendering it, just copying it to ${main.basedir} (defaults to ${basedir}, i.e. the root of the project). If there are any changes in the README it will then show up after a Maven build as a modified file in the correct place. Just commit it and push the change.

Working with the code

如果您没有 IDE 首选项,我们建议您在使用代码时使用 Spring Tools Suite 或 Eclipse。我们使用 m2eclipse eclipse 插件来获得 maven 支持。只要 IDE 和工具使用 3.3.3 或更高版本的 Maven,其他 IDE 和工具也应该可以正常工作。

If you don’t have an IDE preference we would recommend that you use Spring Tools Suite or Eclipse when working with the code. We use the m2eclipse eclipse plugin for maven support. Other IDEs and tools should also work without issue as long as they use Maven 3.3.3 or better.

Activate the Spring Maven profile

Spring Cloud 项目需要激活‘spring’Maven 概要文件来解析 spring 里程碑和 snapshot 存储库。使用您首选的 IDE 激活该概要文件,否则您可能会遇到构建错误。

Spring Cloud projects require the 'spring' Maven profile to be activated to resolve the spring milestone and snapshot repositories. Use your preferred IDE to set this profile to be active, or you may experience build errors.

Importing into eclipse with m2eclipse

我们建议在使用 eclipse 时使用 m2eclipse eclipse 插件。如果您尚未安装 m2eclipse,可以通过“eclipse marketplace”获得它。

We recommend the m2eclipse eclipse plugin when working with eclipse. If you don’t already have m2eclipse installed it is available from the "eclipse marketplace".

旧版本的 m2e 不支持 Maven 3.3,因此一旦项目导入 Eclipse,您就还需要告知 m2eclipse 为这些项目使用正确的个人资料。如果您看到很多与项目中 POM 相关的不同错误,请检查您的安装是否是最新的。如果您不能升级 m2e,请将“spring”个人资料添加到您的 settings.xml。或者,您可以将存储库设置从父 POM 的“spring”个人资料复制到 settings.xml 中。

Older versions of m2e do not support Maven 3.3, so once the projects are imported into Eclipse you will also need to tell m2eclipse to use the right profile for the projects. If you see many different errors related to the POMs in the projects, check that you have an up to date installation. If you can’t upgrade m2e, add the "spring" profile to your settings.xml. Alternatively you can copy the repository settings from the "spring" profile of the parent pom into your settings.xml.

Importing into eclipse without m2eclipse

如果您不想使用 m2eclipse,可以使用以下命令生成 eclipse 项目元数据:

If you prefer not to use m2eclipse you can generate eclipse project metadata using the following command:

$ ./mvnw eclipse:eclipse

可以通过从 file 菜单中选择 import existing projects 导入生成的 eclipse 项目。

The generated eclipse projects can be imported by selecting import existing projects from the file menu.