问题
I have the following structure
root
|- foo
| |- implementation
| | \- build.gradle
| \- interface
| \- build.gradle
|
|- bar
| |- implementation
| | \- build.gradle
| \- interface
| \- build.gradle
|
|- build.gradle
\- settings.gradle
in settings.gradle I have the following:
include ':foo:implementation', ':foo:interface'
include ':bar:implementation', ':bar:interface'
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 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(":", "-")
}
}
}
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.
Any idea?
回答1:
So far, I've only been working with "single dir level" multiprojects; For that scenario, there are several ways to fix it:
- 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...
回答2:
Sadly this is a bug with Gradle; see the open GitHub issue.
回答3:
One (workaround) solution is to use different groups for the subprojects:
// root/foo/build.gradle
subprojects {
group = 'org.example.foo'
}
// root/bar/build.gradle
subprojects {
group = 'org.example.bar'
}
来源:https://stackoverflow.com/questions/26407340/gradle-sub-sub-projects-with-same-name-in-does-not-work-for-eclipse