buildship icon indicating copy to clipboard operation
buildship copied to clipboard

multi modules project cannot be imported successfully

Open CsCherrYY opened this issue 2 years ago • 4 comments

Expected Behavior

The project is imported successfully

Current Behavior

There are serveral errors about type is not accessible and module can not be resolved. image

Steps to Reproduce

  1. given sample project from https://docs.gradle.org/current/samples/sample_java_modules_multi_project.html
  2. try to import it in eclipse
  3. 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.

CsCherrYY avatar Oct 27 '22 02:10 CsCherrYY

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.

donat avatar Nov 09 '22 15:11 donat

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.

CsCherrYY avatar Nov 10 '22 08:11 CsCherrYY

I'm seeing the same problem in my own multi project application.

mcooper7290 avatar Nov 21 '22 03:11 mcooper7290

@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?

CsCherrYY avatar Nov 30 '22 11:11 CsCherrYY