摇篮 - 从模块继承库 [英] Gradle - inherit repositories from a module

查看:112
本文介绍了摇篮 - 从模块继承库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我解释一下我的项目设置。我使用的话项目/模块的Andr​​oid Studio中使用。

First of all, I explain my project setups. I use the words Project/Module as used in Android Studio.

我有我的项目,像以下内容的设置:

I have a setup of my projects like following:


  • LibraryProject =>一个项目,只是我的组库,我在其他项目中使用,如果需要的话

  • LibraryProject => a project that just groups my libraries, that I use in other projects, if necessary


  • BackupLibrary(模块)

  • DatabseLibrary(模块)

  • MainUtilityLibrary(模块)

  • DialogLibrary(模块)

MyProject1

MyProject1


  • 应用程序(项目)

  • DialogLibrary(模块,从DIRFFERENT项目中引用)

我的PROJECT1现在看起来如下:

1)我引用模块从其他项目中,我想用(在完成settings.gradle(项目设置)文件:

1) I reference the module from the other project, that I want to use (done in settings.gradle (Project Settings) file:

include ':app'

include ':dialogLibrary '
project(':dialogLibrary ').projectDir = new File(settingsDir, '../LibraryProject/DialogLibrary ')

2)我添加外库模块作为一个依赖于我的应用程序的的build.gradle

dependencies {
    compile project(':dialogLibrary ')
}


我的LibraryProject看起来像以下内容:

我添加该存储库并直接依赖到模块的`的build.gradle'(这是足以建立它自己的模块没有问题):

I add the repository and the dependency directly to the module's `build.gradle' (this is enough to build the module on it's own without a problem):

allprojects {
    repositories {
        maven { url 'https://dl.bintray.com/drummer-aidan/maven' }
    }
}

dependencies {
    compile 'com.afollestad:material-dialogs:0.7.5.2'
}


问题

的设置迄今不为MyProject1工作。我要补充行家{URLhttps://dl.bintray.com/drummer-aidan/maven'} 来MyProject1为好,编制项目(':dialogLibrary')是不够的。我要补充一点,应该以某种方式从LibraryModule到MyProject1项目的build.gradle 继承又像以下的依赖:

The setup so far does not work for MyProject1. I have to add maven { url 'https://dl.bintray.com/drummer-aidan/maven' } to MyProject1 as well, the compile project(':dialogLibrary ') is not enough. I have to add the dependency that should somehow be inherited from the LibraryModule to MyProject1 Project build.gradleagain like following:

allprojects {
    repositories {
        mavenCentral()
        maven { url 'https://dl.bintray.com/drummer-aidan/maven' } // com.afollestad:material-dialogs
    }
}

否则,我不能编译我的项目。这种方式似乎喜欢做两次的东西,大概可以自动完成。但是如何?这样一来,每当我包括我的LibraryProject一个模块,我要检查,如果我需要一个额外的maven回购...

Otherwise, i can't compile my project. This way seems like doing something twice that probably can be done automatically. But how? This way, whenever I include a module from my LibraryProject, I have to check if I need an additional maven repo...

推荐答案

我认为这与事实摇篮已经没有了 LibraryProject 的知识做设置同时建立 MyProject1 .gradle文件。因此,它包含了 dialogLibrary ,就好像它是它自己的正常子项目。这就解释了为什么Maven的回购协议是不知道 MyProject的的原因; LibraryProject 的配置尚未加载。

I think it has to do with the fact that Gradle has no knowledge of the LibraryProject's settings.gradle file while building MyProject1. So it includes the dialogLibrary as if it is a normal subproject of it's own. This explains the reason why the Maven repo is not know to MyProject; LibraryProject's configuration has not been loaded.

也许你可以包括 dialogLibrary 通过 LibraryProject ?虽然我做了一些测试,无法得到它的工作。它可能有摇篮的限制做的。有一个关于多个settings.gradle文件的计算器后<一个href=\"https://stackoverflow.com/questions/12154031/multiple-settings-gradle-files-for-multiple-projects-building/\">here.

Maybe you can include the dialogLibrary through the LibraryProject? Although I did some testing and could NOT get it to work. It probably has to do with a limitation of Gradle. There is a StackOverflow post about multiple settings.gradle files here.

一个变通可能是建LibraryProject的模块,并用它们来代替。例如建立DialogLibrary到一个罐子,把它上传到Maven仓库,比你的App项目只包含DialogLibrary正常的依赖(不要忘了包括Maven的回购)。

A work around could be to build the Modules of the LibraryProject and use them instead. For example build the DialogLibrary to a jar, upload it to a Maven repository and than in your App project just include DialogLibrary as normal dependency (don't forget to include the Maven repo).

这篇关于摇篮 - 从模块继承库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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