简体   繁体   中英

How can I set in build.gradle the groovy nature of an Eclipse project?

After running gradle cleanEclipse Eclipse on the project it loses the Groovy nature. How can I set this nature automatically, or simply to say to the Gradle to leave it alone.

Edit: According do doc , I can write in the build.gradle:

eclipse {
  project {
    natures 'some.extra.eclipse.nature', 'some.another.interesting.nature'
  }
}

But what is the name of the groovy nature, or how could I get it?

I go to the .project and look:

<natures>
    <nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
    <nature>org.eclipse.jdt.core.javanature</nature>
    <nature>bndtools.core.bndnature</nature>
</natures>

org.eclipse.jdt.groovy.core.groovyNature - that is the nature name

And I am adding apply plugin: "groovy" , as @Peter Niederwieser advised (thanks+1)

But

After running gradle cleanEclipse Eclipse I have correct .project file, and the project has "G" on the icon, but in the .classpath two lines are not present:

<classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/>
<classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>

That ARE present, when I am setting the Groovy nature by hand.

And it seems, that these lines are important, for in that variant the project shows errors even on compile level - it doesn't see some Groovy methods.

Thinking about this again, Gradle will add a Groovy nature for those projects that have the groovy (or groovy-base ) plugin applied. So either add that plugin on the Gradle side, or don't run cleanEclipse after you have added the Groovy nature manually, or switch to the Eclipse Gradle tooling instead of generating Eclipse files.

It seems, that for a real groovy nature setting, I need not only to set

natures.add 'org.eclipse.jdt.groovy.core.groovyNature'

and

apply plugin: "groovy"

, but also to edit the classpath.

eclipse {
    classpath {
        file {
            withXml {
                Node node = it.asNode()
                node.appendNode('classpathentry',[exported:"true",kind:"con",path:"GROOVY_SUPPORT"]) 
                node.appendNode('classpathentry',[exported:"true",kind:"con",path:"GROOVY_DSL_SUPPORT"])
            }
        }
    }
}

What is interesting, if we turn on the groovy classpath by hand, only the path "GROOVY_SUPPORT" appears in the .classpath file. It is also enough for my project. But when turning by hand the whole Groovy nature, both paths appear. So, I am better including them both, too.

The Gradle-Eclipse plugin (that is gradle tooling for Eclipse, not the Eclipse plugin for gradle). Should be installable on Eclipse 3.6. (I say should be installable because we no longer test on 3.6, but there shouldn't be any reason why it is broken). If you install this plugin, you should be able to import your gradle project into Eclipse without calling gradle Eclipse .

You can install from the update site here:

http://dist.springsource.com/release/TOOLS/gradle

And more information on the project is here:

https://github.com/SpringSource/eclipse-integration-gradle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM