Can no longer remove java nature and build command


I just noticed that I am no longer able to remove the Java nature and the Java Builder from a project using Buildship 3.1.6 and Gradle 8.1.

I have recently updated our multi-project build from Gradle 6.9. I am not quite sure when exactly this happened. I am only seeing this now while testing a newer Eclipse version with JDK 17 set as default.

I have configured Eclipse Feature projects and EAR projects to not contain the Java nature (org.eclipse.jdt.core.javanature) and the Java builder (org.eclipse.jdt.core.javabuilder) using the following code in the build file:

apply plugin: 'eclipse'

eclipse {
    project {
        println "buildCommands (before): $buildCommands"
        buildCommands.removeAll { == 'org.eclipse.jdt.core.javabuilder' }
        buildCommand 'org.eclipse.pde.FeatureBuilder'
        println "buildCommands (after): $buildCommands"

        println "natures (before): $natures"
        natures.removeAll {	it == 'org.eclipse.jdt.core.javanature' }
        natures 'org.eclipse.pde.FeatureNature'
        println "natures (after): $natures"

The removal worked previously but now both are always added.

The output of the println statements is for debugging this issue and it looks like this:

> Configure project :

buildCommands (before): [BuildCommand{name='org.eclipse.jdt.core.javabuilder', arguments={}}]
buildCommands (after): [BuildCommand{name='org.eclipse.pde.FeatureBuilder', arguments={}}]
natures (before): [org.eclipse.jdt.core.javanature]
natures (after): [org.eclipse.pde.FeatureNature]

It still looks correct but at the end the .project file contains both entries and the file
org.eclipse.jdt.core.prefs is also created.

It looks like Buildship would be assuming that every project is a Java project. Since the code to remove the Java nature and builder has been in my build file for quite a while I think this was always the case. I would like to get an explanation for this also. → See my first two replies for an explanation.

Anyway, now I cannot find any way to remove these unwanted natures and builders.

Am I doing something wrong?

I also tried the withXml callback on the project file but had the same effect:

eclipse.project.file.withXml { provider ->
    def node = provider.asNode()

    def natures = node.natures.nature
    def javaNature = natures.find{ it.text() =='org.eclipse.jdt.core.javanature' }

    def buildCommands = node.buildSpec.buildCommand
    def name = { it.text() == 'org.eclipse.jdt.core.javabuilder' }
    def buildCommand = name.parent()

    println provider



Further investigation shows that this might be a self-made problem. I have a plugin for features that applies the Java plugin and I wasn’t aware of this. I will remove the application of the Java plugin and report back :wink:

So indeed the plugin to build the Eclipse Feature was applying the JavaPlugin. I removed this and now the project file for the feature projects will no longer contain the two Java-related entries. BUT only after I remove them from the .project file once!

The EAR projects are built using the EarPlugin and that one is applying the JavaBasePlugin. I cannot change that.

So previously this wasn’t really an issue because I was able to remove all natures and build commands and then add exactly the ones I need. This seem to be broken now an I am still looking for an answer to it.

Can you try using eclipse.project.file.whenMerged?