How to prevent linked resources in Eclipse?

On a “Refresh Gradle Project” Buildship add some sources as linked resources from the build.gradle. Eclipse can not good handle this. Is there an option to prevent this?

You are probably including source folders that are outside of your project directory. The only way to do that in Eclipse is with linked resources. So if you don’t want them, don’t include external source folders.

I’d be curious what you mean by “does not handle them well”? Linked resources work fine for me.

On the continuous build server I need the additional source folders. In Eclipse I does not need it. There are additional Eclipse projects (not Gradle projects)

Many features does not work with linked sources. For example the repository functions. It is not possible to commit, update, see the history on linked resources.

So if you don’t want them, don’t include external source folders.

How can I do this in Eclipse? It there a special environment variable to detect that the script run inside Gradle?

If you don’t need them, then you can remove them from the .project and .classpath like this:

eclipse {
  project.linkedResources = []
  classpath.file.whenMerged {
    entries.removeAll {
      it.path.contains('..')
    }
  }
}

If I try this then I receive the follow error:

Caused by: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method eclipse() for arguments [build_3195byk41jk6sicx0c4lejdp6$_run_closure10@178caaf] on root project 'CC' of type org.gradle.api.Project.
	at org.gradle.internal.metaobject.AbstractDynamicObject.methodMissingException(AbstractDynamicObject.java:182)
	at org.gradle.internal.metaobject.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:167)
	at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.java:79)
	at build_3195byk41jk6sicx0c4lejdp6.run(C:\workspace_trunk\CC\build.gradle:252)
	at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:91)

You need to apply the eclipse plugin to your project.

Thank you very much. It works. I have reduce it to:

apply plugin: 'eclipse'
eclipse {
    project.linkedResources = []
}
2 Likes