文档

本地开发环境准备

引导开发者首次进行 TPP 方案开发工作之前的环境准备工作,包含依赖软件安装,阿里云 Maven 仓库加速。

开发环境依赖准备

安装依赖软件

TPP 的方案开发工作,依赖标准的 Java 开发环境,需要准备好以下依赖

  • codeup阿里云提供的免费代码仓库,用于上传方案代码,并用于构建方案环节。

  • jdk 1.8请根据本地操作系统,下载最新的版本的 JDK 8。

  • maven 3.5代码项目本地构建依赖 Maven,请使用 3.5 以上版本,建议 3.5.8。

  • IDE 任意熟悉的 Java 集成开发环境(IDE),社区流行的版本或者文本编辑器。

使用阿里云Maven中央仓库加速 jar 包下载

默认情况下,Maven 会从 Central 仓库下载依赖,下载速度较慢,推荐使用中国内地的镜像进行加速。

阿里云提供了 阿里云Maven中央仓库,解决中国内地开发者加速 Maven 依赖下载的需求。(详情见 https://developer.aliyun.com/mvn/guide

常规情况下, Maven 默认(当前账号)settings.xml 文件存储于用户目录下的 .m2/settings.xml

  • Mac OS 或者 Linux$HOME/.m2/settings.xml

  • Windows\Users\<username>\.m2\settings.xml

Maven 提供了灵活规范的配置选项,下文列举了几种快速配置 Maven 环境的办法。

使用单独的 settings.xml(推荐)

对于不熟悉复杂 Maven 配置的开发者,建议使用单独的 settings.xml,规避因为配置错误引起开发环境问题。这里有以下几种方式可以参考

  1. 全局配置方式:放到上文列举的 settings.xml 文件位置,作为全局配置,将覆盖任意在当前账号执行 Maven 时使用的仓库地址。

  2. 命令行参数方式:将 settings 文件保存到任意方便使用的位置,比如 /example/abc/,通过 mvn -s /example/abc/settings.xml,仅影响这一次 mvn 命令行。

  3. IDEA 配置方式:将 settings 文件保存到任意方便使用的位置,比如 /example/abc/,修改自己的 IDE(集成开发环境),配置 maven settings 文件地址到 /example/abc/settings.xml,使得 IDE 能够使用这个 settings 文件作为运行 Maven 时使用的配置文件。

以下是由 TPP 开发团队提供的 settings.xml 文件,请复制并保存到本地文件,文件编码保存为 UTF-8

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd">
    <mirrors>
        <mirror>
            <id>maven-mirror</id>
            <mirrorOf>central</mirrorOf>
            <name>maven public mirror</name>
            <url>https://repo1.maven.org/maven2/</url>
        </mirror>
    </mirrors>
    <profiles>
        <profile>
            <id>aliyun</id>
            <repositories>
                <repository>
                    <id>aliyun</id>
                    <url>https://maven.aliyun.com/repository/public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>

            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>aliyun</id>
                    <url>https://maven.aliyun.com/repository/public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>aliyun</activeProfile>
    </activeProfiles>
</settings>

这份配置默认从 aliyun 镜像仓库下载 Jar 包。

对于 aliyun 仓库中未收录的版本,缺省从中心仓库下载(可能存在 1 至 2 天的同步延迟,仅影响刚刚发布到中心仓库的版本)

已有 Settings 文件修改定制,加入阿里云 Maven 仓库

针对已经使用过 Maven 的用户,需要小心改动,避免破坏 Maven 配置引起开发环境问题。

  1. 再次建议,参考上文单独 settings 文件部分,在任意路径保存 settings.xml,并修改 maven 命令参数或者 IDEmaven 项目配置文件路径。

  2. 继续查看本文,修改现有的 settings 文件,因为 aliyun maven 仓库加速不仅仅适用于 TPP 提供的 SDK,同时也是一个中央仓库加速的普适方案。

注意:以下操作需要熟悉 XML 标记语言,并且对 Maven 配置文件有一定的了解。

首先:在 settings 文件的 profiles 部分,加入 idaliyun (仅供参考,如果有冲突 ID,请使用自定义名称)的新 profile 配置,注意它不会自动生效,请看下文。

    <profiles>
        <profile>
            <id>aliyun</id>
            <repositories>
                <repository>
                    <id>aliyun</id>
                    <url>https://maven.aliyun.com/repository/public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>

            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>aliyun</id>
                    <url>https://maven.aliyun.com/repository/public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>

除了新增 profile,还需要 activeProfiles 加入上面的profile "aliyun" (如果使用了自定义 ID, 请按实际情况修改)

如果同时存在多个 activeProfile,可能引起相互覆盖,导致阿里云仓库不生效,需要根据实际情况自行判断。

<activeProfiles>
<activeProfile>aliyun</activeProfile>
</activeProfiles>

  • 本页导读 (0)
文档反馈