# 4.1 - 开源插件的构建

在前面很多地方我们已经介绍了 **GitHub** 网站，而插件作者把自己的插件开源但在 **SpigotMC** 等平台提供付费下载。对于只想研究该插件、没有充足资金的服主来说，学会自己构建它们也可以省下一笔支出，但需要注意的是，这么做以后作者是不会给你提供服务支持的，遇到问题、提交建议等一般都需要自己解决，除非作者声明了付费用户和自行构建用户不区别对待。

## IntelliJ IDEA 的下载与安装

点击 [此链接](https://www.jetbrains.com/idea/download/download-thanks.html?platform=windows\&code=IIC) 下载，安装与常规软件并无差异，在此不再赘述，实在不会的请自己查询。

## 从 GitHub 上克隆项目

打开软件后，点击“从VCS获取”，在打开的页面中输入 GitHub 的地址即可。

![](/files/TXyLreqcOgiOpvr6RmGg)

## 进入项目

进入项目后，IntelliJ IDEA 会自动开始构建项目，如果并没有，点击图片所示的图标即可。构建项目中的主要过程就是下载依赖。

<figure><img src="/files/mLyiKk7gO9pYxpbIMjAQ" alt=""><figcaption></figcaption></figure>

如果这个过程中出现下载依赖方面出现问题，可以着手以下两个方法：

* 使用镜像节点。
* 使用代理。以 Clash 为例，你需要在常规选项卡开启 TUN 模式。

## 打包 jar

一般开源项目会自带构建、打包插件成 **jar** 文件的 **gradle** 或者 **maven** 文件。使用 **maven** 作为构建、打包工具的项目源代码会含有 **pom.xml** 文件，而 **gradle** 则是很好就可以辨别出来。

知道插件使用的构建、打包工具后就可以开始着手打包了：

* 在上图所指图标右侧有一个 **添加配置** 按钮，请点击它。
* 在打开的新页面中点击 **添加新的运行配置** 按钮。
* 在再次打开的新界面中找到对应的构建、打包工具，例如这里是 **gradle**。
* 在再次打开的新页面中的运行字段框中输入打包指令。**gradle** 输入 **clean build**，**maven** 输入 **clean package**。

<figure><img src="/files/sYxjJCoHFPle6QEjqXln" alt=""><figcaption></figcaption></figure>

* 打包完成。

<figure><img src="/files/O74hbHmGIOT27nElcMp4" alt=""><figcaption></figcaption></figure>

## 添加本地库

本地库可以在 **Maven** 或者 **Gradle** 的构建文件添加。

{% hint style="info" %}
**请注意，如果添加的 jar 文件下又需要添加其他 jar 文件作为依赖，那么添加本地库需要将这些所有用到的 jar 文件全部打包。**

**例如，在下面这个例子中使用了 GamePoints 插件作为依赖打包，而 GamePoints 又用了其前置插件 NexEngine 作为依赖，因而我将两个插件都写进了这个构建文件中。**
{% endhint %}

对于 **Maven**，打开项目下的 `pom.xml` 文件，找到如下格式的内容：

```
    <dependencies>
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot-api</artifactId>
            <version>1.19.1-R0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>su.nightexpress.gamepoints</groupId>
            <artifactId>GamePoints</artifactId>
            <version>1.3.5</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/GamePoints-1.3.5.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>su.nexmedia</groupId>
            <artifactId>NexEngine</artifactId>
            <version>2.2.8</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/NexEngine.jar</systemPath>
        </dependency>
    </dependencies>
```

然后将对应的 **jar** 文件放置到项目文件夹下的 **libs** 文件夹即可。

**Gradle** 就比较简单了，找到 `build.gradle`，在：

```
dependencies {
  ...（一系列内容）
}
```

中添加：

```
compileOnly fileTree(dir:'libs',includes:['*.jar'])
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.superiormc.cn/new-user-doc/fu-zhu-ye-yao-hui-yi-dian-zhe-xie/4.1-kai-yuan-cha-jian-de-gou-jian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
