Gradle + Eclipse plugin: Add AspectJ nature into projects

I have found nice script for adding AspectJ nature into Eclipse project using Gradle. See . Unfortunately each run of ‘gradle eclipse’ adds new nodes into project XML. Here is my fix of that issue:

eclipse.project.file.withXml { xmlProvider->
  def projectDescription = xmlProvider.asNode()
  def xmlparser = new XmlParser()

  def builders = projectDescription.buildSpec[0]

  if (!builders.buildCommand.any {[0].value()=='org.eclipse.ajdt.core.ajbuilder'}) {
    def ajbuilder = xmlparser.createNode(builders, 'buildCommand', [:])
    xmlparser.createNode(ajbuilder, 'name', [:]).setValue('org.eclipse.ajdt.core.ajbuilder')
    xmlparser.createNode(ajbuilder, 'arguments', [:]);

  def natures = projectDescription.natures[0]

  if (!natures.nature.any {it.value()=='org.eclipse.ajdt.ui.ajnature'}) {
    def ajnature = xmlparser.createNode(null, 'nature', [:])
    natures.children().add(0, ajnature)

Then all nodes are created only once.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s