Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ch.32): Close #17: Gradle Cheatsheet #71

Open
wants to merge 4 commits into
base: bleeding
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat(ch.32): encoding, publishToMavenLocal
3TUSK committed May 4, 2020
commit adad407752e49af925258f3644367a0f2d09496a
1 change: 1 addition & 0 deletions chapter-32/index.md
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ Gradle 的存在让我们可以直接一行 `gradle build` 命令就能搞定编
- 信息安全
- Jar 签名
- [构建与发布](./publish/index.md)
- [强制指定编码方式](./publish/encoding.md)
- Shadow/Shade
- [`publishToMavenLocal` 任务](./publish/local.md)
- CurseGradle
16 changes: 16 additions & 0 deletions chapter-32/publish/encoding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 强制指定编码方式

出于跨平台的考虑,习惯上 Mod 编译时使用 UTF-8 编码方式对字符进行编码。
但是 Windows 家族的操作系统的默认编码方式不是 UTF-8。
这可能会导致构建时因为出现所谓的“非法字符”而导致构建失败。你可以通过在 `build.gradle` 的结尾加上这样一段来强制指定编码方式:

```groovy
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
```

## `JavaCompile`?

是的,这个选项是在 `JavaCompile` 这一个 task type 下的。
如果你的 Mod 里还有别的类型的源码,换成对应的 task type 即可。
20 changes: 20 additions & 0 deletions chapter-32/publish/maven-local.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 发布到本机 Maven 仓库

一个 Maven 仓库的本质是有特殊目录格式的目录,或称文件夹,可通过一串 URL 索引。

所以你大可以把你电脑上某个目录改装成 Maven 仓库。不过我们甚至连改装都不用——因为 `mavenLocal()` 已经在那了。

## `publishToMavenLocal`

在命令行中执行

```
./gradlew publishToMavenLocal
```

然后你的 Mod 就会去本机的 `mavenLocal()` 仓库里了。
一般来说,这个仓库的真实位置是 `${USER_HOME}/.m2/`,也就是说:

- 对于 Windows,是 `%USERPROFILE%/.m2/`。基本上就是 `C:\Users\[用户名]\.m2`。
- 对于 Linux、macOS 等深受 Unix 影响的系统,是 `$HOME/.m2/`
- 或者说是 `~/.m2`,如果你用的 Shell 支持展开 `~`。