jitpack打包
1.添加依赖
在gradle.build文件中,应用插件:maven或者maven-publish
1 | |
如果是新版gradle,应用插件可以使用plugins{}取代apply plugin写法。例如:
1 | |
如果应用的maven插件,可以使用下面命令在本地测试打包情况
1 | |
如果使用的maven-publish插件,可以使用下面命令在本地测试打包情况
1 | |
2.更改build.gradle
示例代码:来自jitpack官方
Simple - https://github.com/jitpack/gradle-simple
Example Gradle project producing a single jar. Uses the maven plugin to publish the jar to the local repository.
https://jitpack.io/#jitpack/gradle-simple
To install the library add:
1 | |
build.gradle文件示例内容
1 | |
Multiple modules - https://github.com/jitpack/gradle-modular
Example gradle project with two modules:
- client
- server
To install each module individually use com.github.User.Repo for groupId and module name as artifact id:
1 | |
build.gradle文件示例内容
1 | |
Project with multiple artifacts - https://github.com/jitpack/gradle-multiple-jars
Example Gradle project producing two jars from single source directory:
- API from src/api
- Impl from src/impl
Both jars are installed to local maven reactor with:
1 | |
To add them to build.gradle use the following syntax:
1 | |
Or to add them both together:
1 | |
build.gradle文件示例内容
1 | |
3.打包和发布
3.1公开库
3.2私有库
3.2.1 总览-以私有库为例
使用github账号登录Jitpack,点击settings
输入自己的私有库地址,点击
Generate生成SSH keys把jitpack.io生成的ssh-key粘贴到自己的私有工程中,配置访问权限。
1
2
3私有库的设置页面,在"deploy keys"下面点击 “add deploy keys”
点击 “add deploy keys”之后,添加key,配置访问权限。
不用勾选页面下方的“Allow write access”在github上生成relase,之后在jitpack.io中,查找自己的库,点击Look up出现我们的release版本
3.2.2 setup
要开始使用私有存储库,您首先需要授予 JitPack 访问权限。打开https://jitpack.io/private并按照以下步骤操作:
单击授权以获取您的个人身份验证令牌。您团队的每个成员都应该获得自己的令牌。
将令牌添加到 $HOME/.gradle/gradle.properties:
authToken=AUTHENTICATION_TOKEN然后在 build.gradle 中使用 authToken 作为用户名:
1 | |
做完这一步,自己就可以不用公开存储库,而是可以直接使用了。
如果要让其他人可以使用,参考下面的两种分享方法
问题:按照官网的写法但是使用的时候jitpack -从服务器收到状态代码521/401/403
因为您在 gradle.properties 中定义了 jitpack 令牌,但您没有将其指向那里,只需复制并粘贴下面在 gradle 属性中使用 jitpack 令牌的代码和应该能正常工作
1 | |
3.2.3 公开分享
在某些情况下,您希望公开发布您的项目,同时保持源代码的私密性。在这种情况下:
- 使用具有推送权限的用户登录
- 查找您的私人存储库
- 点击设置图标
- 单击 Lock 图标以公开此库
3.2.4 私有分享
任何对您的 Git 存储库具有读取权限的人都可以下载构建工件。您还可以在 JitPack.io 上添加对构建工件具有读取权限的其他协作者。他们将无权访问源代码。
添加协作者:
- 使用具有推送权限的用户登录
- 查找您的私人存储库
- 点击设置
- 添加合作者 GitHub 用户名
合作者需要登录 JitPack.io 以获得他们自己的身份验证令牌。
问题
说没有gradle-wrapper
这个文件是gradle的包装,在不同的环境下不同的gradle版本中确保编译顺利,所以,版本库里不能把他忽略。
如果git的忽略文件中的规则把他忽略了(比如忽略文件中的规则 : *.jar),可以使用git add -f gradle-wrapper.jar 强制添加
Entry META-INF/DownloadEngine.kotlin_module is a duplicate but no duplicate handling strategy has been set.
- Try adding this to your build.gradle . in packagingOptions:
1 | |
Looks like a cache error (with kotlin) to me. Running
gradle cleanorgradle clear(not sure which is the right spelling, sorry, one of these should exist as a gradle task) and rebuilding should fix the error, because all files in cache will be deleted by the task and regenerated by the project build.1
./gradlew clean
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!