了解“存储库"标签 [英] Understanding "repositories" tags

查看:270
本文介绍了了解“存储库"标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑,为什么在Android项目的多个地方都需要相同的 repository 标签.为什么我们不将所有存储库都放在一个标签下,然后编译器从那里搜索所有内容.

I am confused why same repositories tags are required in multiple places in an Android project. Why don't we have all repositories under one tag, and the compiler searches everything from there.

我的特殊情况是:

我创建了一个库模块并将其添加到项目中.在我的图书馆gradle文件中,我有:

I created a library module and added it in a project. In my library gradle file, I have:

implementation 'com.github.jkwiecien:EasyImage:1.3.1'

我在库的gradle文件的 repositories 标签中为其添加了 maven {url"https://jitpack.io"}

.我只希望EasyImage在库中,而不在项目中.但是,直到我在Project的 app/build.gradle 文件中添加了相同的 jetpack.io 后,它才能编译.为什么我们需要这样做?

for which I added maven { url "https://jitpack.io" } in repositories tag in the library's gradle file. I want EasyImage in the library only, not in the project. But it wont compile until I added this same jetpack.io in Project's app/build.gradle file. Why do we need to do this?

我想破坏我的图书馆,并且我不想让用户添加已经在我的图书馆中添加的东西,而不是他们的项目所必需的.

I want to distrubute my library and I don't want the users to add things that are already added in my library and are not required by their project.

推荐答案

如果将jitpack储存库网址放在项目级别的build.gradle中,而不是应用程序级别的build.gradle中,则这两种方法都适用.当您将库上传到JitPack时,它会自动为您构建"您的库,但是在您的情况下,您的库是在本地构建的,因此它需要每个构建文件中的存储库URL来分别构建它们.但是,您应该将存储库URL保留在您的库中,因为最终您将分发它,并且如果您在项目build.gradle文件中使用url而不是存储库,则JitPack将无法构建您的库模块.

If you put jitpack repository url in your Project level build.gradle instead of app level build.gradle it will work for both. When you upload your library to JitPack, it automatically 'builds' your library for you but in your case your library is being built locally so it needs the repository url in each build file to build them separately. However you should keep the repository url in your library because eventually you will be distributing it and JitPack won't be able to build your library module if you have the url in your project build.gradle file instead of repository.

上一个答案:据我了解:您正在库中使用EasyImage,并且将库添加到项目中时,要使用库中加载的EasyImage库,而不是将其添加到项目中.

Previous Answer: From what I understand: You are using EasyImage in your library, and when you add the ibrary to your project, you want to use the same EasyImage library that you loaded in your library instead of adding it to your project.

如果您使用实现"这样加载库:

if you load your library using 'implementation' like this:

implementation 'com.github.you:yourlibrary'

您将无法访问您的图书馆"使用的依赖项.但是,如果您使用"api"加载它

you will not be able to access dependencies that 'yourlibrary' uses. But if you load it using 'api'

api 'com.github.you:yourlibrary'

现在您可以从此库访问EasyImage,而无需再次添加.

Now you can access EasyImage from this library instead of adding it again.

它是在Gradle 3.0中添加的,其工作方式与工作时使用的"compile"关键字相同(现已弃用).您应该查看本文以获得详细说明

This was added in Gradle 3.0 and it works the same way as 'compile' keyword used to work(which is deprecated now). You should checkout this article for detailed explanation.

为什么会这样?:
通过使用imepentation,如果更改EasyImage中的任何实现,则Gradle只需重新编译EasyImage即可,并且您的库就像未直接导入您的库的任何其他类不能使用它的任何实现一样.

Why this behavior?:
By using imepentation, if any implementation in EasyImage is changed, Gradle just needs to recompile EasyImage and Your library as any other class which does not import your library directly cannot use any implementation of it.

但是,如果您使用api加载库,则如果EasyImage内部实现了任何更改,则gradle需要重新编译EasyImage,您的库以及导入该库的所有其他模块就像其他任何模块一样,可能会使用EasyImage的实现(例如您的应用)

But if you use api to load library, If any change is implemented inside EasyImage, gradle needs to recompile EasyImage, Your library and all other modules which import your library as any other module might use implementation of EasyImage (like your app).

这篇关于了解“存储库"标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆