Hi,
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 { it.name == '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' }
javaNature.parent().remove(javaNature)
def buildCommands = node.buildSpec.buildCommand
def name = buildCommands.name.find { it.text() == 'org.eclipse.jdt.core.javabuilder' }
def buildCommand = name.parent()
buildCommand.parent().remove(buildCommand)
println provider
}
Regards,
Thomas