如何在build.gradle中设置Eclipse项目的groovy性质? [英] How can I set in build.gradle the groovy nature of an Eclipse project?
问题描述
在项目上运行 gradle cleanEclipse Eclipse
后,它会丢失Groovy的性质。如何自动设置这个性质,或者只是简单地对Gradle说一下吧。
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.
编辑:
根据 doc ,我可以在build.gradle中写:
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?
我去.project,看看:
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 - 这是自然名称
org.eclipse.jdt.groovy.core.groovyNature - that is the nature name
我添加了应用插件:groovy
,作为@Peter Niederwieser建议(谢谢+1)
And I am adding apply plugin: "groovy"
, as @Peter Niederwieser advised (thanks+1)
运行 gradle cleanEclipse Eclipse
我有正确的.project文件,并且项目在图标上有G,但在.classpath中,两行不存在:
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"/>
当我手动设置Groovy性质时,现在出现。
That ARE present, when I am setting the Groovy nature by hand.
似乎这些行很重要,因为在该变体中,即使在编译级别,项目也显示错误 - 它没有看到一些Groovy方法。
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.
推荐答案
看来,对于一个真正的groovy自然环境,我不仅需要设置
It seems, that for a real groovy nature setting, I need not only to set
natures.add 'org.eclipse.jdt.groovy.core.groovyNature'
和
apply plugin: "groovy"
,还可以编辑类路径。
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"])
}
}
}
}
有趣的是,如果我们手动打开groovy类路径,则只有路径GROOVY_SUPPORT出现在.classpath文件中。这对我的项目也是足够的。但是当用手转动整个Groovy的性质时,两条路都会出现。所以,我也比较好,包括他们。
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.
这篇关于如何在build.gradle中设置Eclipse项目的groovy性质?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!