Add projectReference to classpath

Based on my research, the eclipse classpath can be modified via the closure ‘whenMerged’.
e.g.:

eclipse {
  project.linkedResource name: 'linked-dir'', type: '2', location: '${(new File("/my/local/dir").)absolutePath}'
    classpath.file.whenMerged {
      entries += new Library(fileReference('linked-dir'))
    }
}

I would like to add a ProjectReference (as a valid implementation of a ClasspathEntry).
Unfortunately my approach via:

    file {
      whenMerged {
        entries = new ProjectDependency('..\\myOtherProject') + entries
      }
    }

fails.
Any hint is highly appreciated.
Thank you in advance.

Add this to your build.gradle file to include the Eclipse project myOtherProject, which already exists in the Workspace:

eclipse {
  classpath {
    file {
      whenMerged { classpath ->
        classpath.entries << new org.gradle.plugins.ide.eclipse.model.ProjectDependency('/myOtherProject')
      }
    }
  }
}

Ole O.

1 Like