中具有相同名称的Gradle子子项目不适用于Eclipse [英] Gradle sub-sub-projects with same name in does not work for eclipse

查看:177
本文介绍了中具有相同名称的Gradle子子项目不适用于Eclipse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下结构

root
|- foo    
|  |- implementation
|  |   \- build.gradle
|  \- interface
|      \- build.gradle
|
|- bar
|  |- implementation
|  |   \- build.gradle
|  \- interface
|      \- build.gradle
|
|- build.gradle
\- settings.gradle

在settings.gradle中,我有以下内容:

in settings.gradle I have the following:

include ':foo:implementation', ':foo:interface'
include ':bar:implementation', ':bar:interface'

在根文件夹的build.gradle中,将它们全部作为依赖项

in my build.gradle on the root folder I put all of them as a dependency

dependencies { 
    compile project(':foo:implementation')
    compile project(':foo:interface')
    compile project(':bar:implementation')
    compile project(':bar:interface')
}

Eclipse需要每个项目使用不同的名称.默认情况下,Gradle使用项目名称在Eclipse中命名它们.因此,eclipse无法在':foo:implementation'和':bar:implementation:'之间进行区分,因为它们在Eclipse中都将被命名为'implementation'.在我看来,应该通过将Eclipse项目名称设置为更具体的名称来解决该问题,例如:

Eclipse needs each project to have distinct names. Gradle by default uses the project name to name these in eclipse. Thus eclipse is unable to distinguish between ':foo:implementation' and ':bar:implementation:' as they both will be named 'implementation' inside Eclipse. In my mind this should have been solvable by setting the eclipse project name to something more specific, e.g.:

allprojects {
    eclipse.project {
        if (project == rootProject) {
            name = rootProject.name
        } else {
            name = rootProject.name + project.path.replace(":", "-")
        }
    }
}

有了这个,我得到了唯一的项目名称,但是当我查看.classpath xml时,仅存在一个实现项目和一个接口项目.

With this I get unique project names, but when I look at the .classpath xml only one of the implementation projects and one of the interface projects are present.

有什么主意吗?

推荐答案

到目前为止,我只在使用单个目录级别"的多项目.对于这种情况,有几种解决方法:

So far, I've only been working with "single dir level" multiprojects; For that scenario, there are several ways to fix it:

  • 如果您只想在Eclipse中修复它,并且使用的是导入gradle项目"向导,则可能需要设置使用分层项目名称"复选框.不知道它在您的情况下的行为(双目录级别)
  • 希望下一个可以帮助您: eclipse插件还提供了更改项目名称的方法,虽然我自己还没有使用过...
  • If you want to fix it for eclipse only and if you're using the "import gradle project" wizard, you might want to set the "Use hierarchical project names" check box. Not sure how it behaves in your case (double dir level)
  • Next one can hopefully help you out: how to rename the project in gradle instead of using folder name?. Probably with some extra investigation for your double dir level. It will also change the gradle project names BTW
  • And indeed, The eclipse plugin also provides means to change project names, haven't used it myself though...

这篇关于中具有相同名称的Gradle子子项目不适用于Eclipse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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