导入Gradle项目

由于项目中的更改,有必要更新Gradle项目的前一年的构建文件。还必须再次导入供应商库,因为必须更新去年的供应商库才能与今年的项目兼容。

自动导入

To make it easy for teams to import previous years gradle projects into the current year’s framework, WPILib includes a wizard for importing previous years projects into VS Code. This will generate the necessary gradle components and load the project into VS Code. In place upgrades are not supported.

重要

The import process copies your project source files from the current directory to a new directory and completely regenerates the gradle files. Additionally, it updates the code for the package changes made in 2022. If you made non-standard updates to the build.gradle, you will need to make those changes again. For this reason, in place upgrades are not supported. It is also necessary to import vendor libraries again, since last year’s vendor libraries must be updated to be compatible with this year’s projects.

启动导入向导

../../../_images/ImportPopup.png

当您打开上一年的项目时,将提示您导入该项目。单击是。

Alternately, you can chose to import it from the menu. Press Ctrl+Shift+P and type “WPILib” or click the WPILib icon to locate the WPILib commands. Begin typing “Import a WPILib 2020/2021/2022 Gradle project” and select it from the dropdown as shown below.

../../../_images/ImportGradleMenu.png../../../_images/VSCodeImport.png

您将看到WPILib项目导入器窗口。这类似于创建新项目的过程,窗口和步骤如下所示。该窗口包含以下元素:

  1. ** Gradle Project **:选择要导入的项目。用户应在gradle项目的根目录中选择build.gradle文件。

  2. 项目位置:确定机器人项目所在的文件夹。

  3. 项目名称:机器人项目的名称。如果选中了“创建新文件夹”框,这还将指定项目文件夹的名称。该目录必须与原始位置不同。

  4. 创建新文件夹:如果选中此选项,将创建一个新文件夹,以将项目保存在先前指定的文件夹中。如果未选中,则项目将直接位于先前指定的文件夹中。如果文件夹不为空且未选中,将引发错误。

  5. 团队编号:项目的团队编号,将用于项目中的程序包名称并在部署代码时定位机器人。

  6. 启用桌面支持:如果选中此选项,则启用仿真和单元测试支持。但是,在某些情况下,这会做一些意想不到的事情。此外,并非所有库都需要所有供应商库的桌面支持。

  7. Import Romi Project: If this is checked, the project is imported using the Romi gradle template. This should only be checked for Romi projects.

单击“导入项目”以开始升级。

The gradle project will be upgraded and copied into the new project directory. You can then either open the new project immediately using the pop-up below or open it later using the Ctrl+O (or Command+O for macOS) shortcut.

Opening Project pop-up in VS CodeTrusted Workspace dialog in VS Code.

Click Yes I trust the authors.

C ++配置(仅C ++)

对于C ++项目,还需要设置IntelliSense。每当您打开一个项目时,您都应该在右下角看到一个弹出窗口,要求刷新C ++配置。单击“是”以设置IntelliSense。

../../../_images/cpp-configurations.png

第三方库

有必要更新和重新导入第三方库。有关详细信息,请参见:第三方库<3rd-party-libraries>