buildship
buildship copied to clipboard
multi modules project cannot be imported successfully
Expected Behavior
The project is imported successfully
Current Behavior
There are serveral errors about type is not accessible and module can not be resolved.
Steps to Reproduce
- given sample project from https://docs.gradle.org/current/samples/sample_java_modules_multi_project.html
- try to import it in eclipse
- can see the errors about modular project
Information
related eclipse bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=576577
I just try to add some snippets into build.gradle to manually add the module attribute to the buildship container:
eclipse {
classpath {
containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
file {
whenMerged {
def source = entries.find { it.path == 'org.eclipse.buildship.core.gradleclasspathcontainer' }
source.entryAttributes['module'] = 'true'
}
}
}
}
and it works. The problem here is that we should automatically add that attribute for entries which should have this attribute.
The eclipse
plugin in Gradle has module support, but unfortunately, it does not add project dependencies to the module path.
I've taken a stab at it and it seems like the algorithm should work as follows: a project dependency should be added to the modulepath (i.e. should have the module=true classpath attribute) if the current project and the target project are both modular. @CsCherrYY wdyt?
The prototype implementation is available here: https://github.com/gradle/gradle/commit/05d5684898e850f3d2da9a3997d85d2a958d42f3. It only modifies EclipseModelBuilder
. The correct approach would be to fix the behavior in the Eclipse plugin. At the same time, the right approach would be to just extract the structural information from Gradle and compute the modulepath in Buildship.
Thanks a lot for investigating. That sounds great to me. I can imagine that the buildship can query a new version of EclipseModel
which contains modular attributes set to true
in your mentioned case. That should be the case, and I'm curious about (maybe a silly question) if users in old Gradle versions can benefit from this change. Since the modified model is only available in the future Gradle versions.
I'm seeing the same problem in my own multi project application.
@donat I just tested your mentioned prototype and it works well in the sample project👍will we propose a new PR in the Gradle repository?