Trying to remove attributes from <classpathentry/>

After I run eclipse task it generates the following .classpath file:

...
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer">
		<attributes>
			<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
		</attributes>
</classpathentry>
...

The problem is that my application is SpringBoot driven, so I don’t need listed attributes since they create red-hairing classpath errors leading to my project being marked as “containing errors”.

I was trying to remove this way:

eclipse.classpath.file {
  beforeMerged { classpath ->
    classpath.entries.find { entry -> entry.path == 'org.eclipse.buildship.core.gradleclasspathcontainer' }*.children().clear()
  }
  whenMerged { classpath ->
    classpath.entries.find { entry -> entry.path == 'org.eclipse.buildship.core.gradleclasspathcontainer' }*.children().clear()
  }
  withXml { xml ->
    def node = xml.asNode()
    def children = node.children()
    children.each {
      if (it.@path == 'org.eclipse.buildship.core.gradleclasspathcontainer') {
        it.children().clear()
      }
    }
  }
}

None of the overrides work, and I’m not sure why.

Gradle version: 4.4

Bumping the topic for higher visibility

The attribute comes from Buildship itself. The relevant logic lives in WtpConfigurator. For the time being there’s no way to change that.

Can you elaborate on what container errors you see? Maybe there are some details in the Problems view?

Bunch of invalid classpath errors that disappear as soon as I remove that attribute from .classpath file:

@donat Any ideas what’s going on?

I haven’t seen this exact error message before. Can you expand those messages (i.e. right-click on them and search for properties)? Or maybe you see something more in the Eclipse log file?

Also, googling the error message gave me an SO thread which might be relevant for your use-case.

If you can’t figure out what’s going on, then please create a minimal example project exhibiting the problem, and I’ll take a look.

One example:

Description Resource Path Location Type
Invalid classpath publish/export dependency …/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.8.0/45b426f7796b741035581a176744d91090e2e6fb/jackson-annotations-2.8.0.jar. The project contains another dependency with the same archive name. …rest P/…rest Classpath Dependency Validator Message

Yep, the posted SO thread is related, but it is maven. They are also advising to modify the classpath, which I did by removing that attribute under <classpathentry path="org.eclipse.buildship.core.gradleclasspathcontainer"> which resolves my errors. And I already tried that before.

BUT my problem is that as soon as I do Refresh gradle project, it automatically restores that attribute by bringing these errors. That’s why I was trying to intercept the creation of the classpath entry during gradle’s classpath.eclipse/Wtp.whenMerged task, but according to you it is not going to work.

@donat Still having this problem :frowning:

So the complete solution is would be to move the entire logic to Gradle and let users customize it in eclipse.classpath.file.whenMerged. It would take too much time and we don’t have many resources allocated to the Buildship project atm, so I think we should provide at least a workaround.

Right now, I don’t see another way around it but to implement a custom plugin configurator plugin. It’s not that hard though, I’ve written a sample for that: https://github.com/donat/buildship-sample-customize-wtp-classpath . Let me know what you think.