[英]How-to integrate latest Groovy (2.4) with latest Netbeans (8.2)?
This question follows-on from notes against Netbeans v8.0.1. 这个问题来自Netbeans v8.0.1的注释。
This question is now critical since I began using Spock for Java testing since it is Groovy based. 自从我开始使用Spock进行Java测试以来,这个问题现在至关重要,因为它基于Groovy。
I like Spock and I'd prefer to work with the same Groovy version within Netbeans, as I use with Gradle and on the command line. 我喜欢Spock ,我更喜欢在 Netbeans中使用相同的 Groovy版本,就像我在Gradle和命令行中一样。
Also, I am using sdkman which means that the " working " Groovy version can swap depending on which project or which version of a package I need to work on. 此外,我正在使用sdkman ,这意味着“ 工作 ”Groovy版本可以交换,具体取决于我需要处理哪个项目或哪个版本的软件包。 In short I want Netbeans to work with ... 总之,我希望Netbeans能够......
At present ... 现在 ...
$ groovy -version
Groovy Version: 2.4.7 JVM: 1.8.0_102 Vendor: Oracle Corporation OS: Linux
$
$ gradle -version
------------------------------------------------------------
Gradle 3.1
------------------------------------------------------------
Build time: 2016-09-19 10:53:53 UTC
Revision: 13f38ba699afd86d7cdc4ed8fd7dd3960c0b1f97
Groovy: 2.4.7
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_102 (Oracle Corporation 25.102-b14)
OS: Linux 4.4.0-36-generic amd64
And when the Groovy and Gradle project runs on the command-line... 当Groovy和Gradle项目在命令行上运行时......
$ gradle build
Starting a Gradle Daemon (subsequent builds will be faster)
Gradle version: 3.1
Groovy version: 2.4.7
Java version: 1.8.0_102
:compileJava
:compileGroovy
...
Running the same Gradle build.gradle
project within Netbeans: 在Netbeans中运行相同的Gradle build.gradle
项目:
Executing: gradle build
Arguments: [-u]
Gradle version: 3.1
Groovy version: 2.4.4
Java version: 1.8.0_102
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
At present I have NO idea where v2.4.4 Groovy came from! 目前我不知道v2.4.4 Groovy来自哪里! Although I am formulating an uncomfortable hypothesis which I'll plonk at the end. 虽然我正在制定一个令人不舒服的假设 ,但最后我会这样做。
With Netbeans there seem to be two different problems which I'll cover separately. 有了Netbeans,似乎有两个不同的问题,我将分别介绍。 I will take the second point first, as it probably impacts the point # 1 more than we realise.. 我会先采取第二点,因为它可能影响点#1比我们更明白..
The documented Groovy configuration process 记录的Groovy配置过程
groovy-all.jar
is enough 建议似乎相信只需将Groovy库更改为最新的groovy-all.jar
This hasn't worked very well at all judging by the relevant questions/comments out there ... 根据那里的相关问题/评论判断,这根本没有奏效......
A mythbuster ... I have been adding this snippet to Groovy and Gradle scripts 一个神话 ...我一直在将这个片段添加到Groovy和Gradle脚本中
println "Gradle version: "+ gradle.gradleVersion;
println "Groovy version: "+ GroovySystem.version;
println "Java version: "+ System.getProperty("java.version");
The output when running with netbeans 8.2 on Windows and Linux is curious. 在Windows和Linux上使用netbeans 8.2运行时的输出很奇怪。
Groovy version: 2.1.3
Java version: 1.8.0_102
I was thinking v2.1.3 is the groovy-all
JAR file that comes with Netbeans -- how silly of me : 我在想v2.1.3是Netbeans附带的groovy-all
JAR文件 - 我多么愚蠢 :
The Netbeans log show me that the Groovy module loaded was: Netbeans日志显示加载的Groovy模块是:
"Groovy 2.1.7" jar:nbinst://org.netbeans.modules.libs.groovy/modules/ext/groovy-all.jar!/ “Groovy 2.1.7”jar:nbinst://org.netbeans.modules.libs.groovy/modules/ext/groovy-all.jar!/
I checked that JAR, and this JAR file reports its version 2.4.5 : 我检查了JAR,这个JAR文件报告其版本2.4.5 :
$ java -jar /opt/dev/netbeans/home/groovy/modules/ext/groovy-all.jar -version
Groovy Version: 2.4.5 JVM: 1.8.0_102 Vendor: Oracle Corporation OS: Linux
Where does Groovy v2.1.3
come from? Groovy v2.1.3
来自哪里? I accidentally found that too. 我也偶然发现了。 I swapped out the bundled (and mislabelled in libraries) v2.1.7 JAR file with the current embedded groovy-all (v2.4.7). 我用当前的嵌入式groovy-all(v2.4.7)替换了捆绑的(并且在标签中用错误标记 )v2.1.7 JAR文件。
When I started Netbeans 8.2 ... I ran my Groovy main program: 当我开始使用Netbeans 8.2时......我运行了我的Groovy主程序:
Gradle version: 3.1
Groovy version: 2.1.3
Java version: 1.8.0_102
Huh ! 嗯 ! No difference ... Now. 没有区别......现在。 Look at the output from a Gradle build under Netbeans (which also runs a Groovy run-time...): 查看Netbeans下的Gradle 构建的输出(也运行Groovy运行时......):
Executing: gradle build
Arguments: [-u]
Gradle version: 3.1
Groovy version: 2.4.4
Java version: 1.8.0_102
:compileJava UP-TO-DATE
:compileGroovy
Summarising; 总结; Netbeans appears to embody the following Groovy run-time versions: Netbeans似乎体现了以下Groovy运行时版本:
And even though I have established a groovy library as: groovy-all-2.4.7.jar
and put this JAR into the Netbeans Groovy modules area: 即使我已经建立了一个groovy库: groovy-all-2.4.7.jar
并将此JAR放入Netbeans Groovy模块区域:
/opt/dev/netbeans/home/groovy/modules/ext
groovy-all.jar
# After copying the embeddable/groovy-all-2.4.7.jar
# into Netbeans Groovy/modules ...
#
$ java -jar /opt/dev/netbeans/home/groovy/modules/ext/groovy-all.jar -version
Groovy Version: 2.4.7 JVM: 1.8.0_102 Vendor: Oracle Corporation OS: Linux
Still NO scripts report the Groovy version as: 2.4.7. 仍然没有脚本报告Groovy版本为:2.4.7。
To mis -quote The Princess Bride , " Groovy integration with Netbeans ... You seem to use this word alot . 错误引用公主新娘 ,“ Groovy与Netbeans融合......你似乎很多时候使用这个词 。
As a counter point; 作为反击点; I found the Gradle configuration ... These language/platform configurations can suit my needs: 我找到了Gradle配置......这些语言/平台配置可以满足我的需求:
Things that don't work well in a Netbeans context are: 在Netbeans上下文中效果不佳的事情是:
Why can't Netbeans support a "Groovy platform" across all components and activities?! 为什么Netbeans不能在所有组件和活动中支持“Groovy平台”?!
Good examples for Groovy would be to look at how Netbeans supports: Groovy的好例子是看Netbeans如何支持:
Whereas Groovy appears to be all over the place. 而Groovy似乎到处都是。 Clearly the use of Library functionality is NOT working. 显然,使用库功能是行不通的。
I want some consistent Groovy language operation with Netbeans. 我想要一些与Netbeans一致的Groovy语言操作。 It this means I need to fiddle with Bundles and get down and dirty, then may be that's a good thing because what I'm experiencing is Unsatisfactory. 这意味着我需要摆弄Bundles并且变得肮脏,那么这可能是件好事,因为我所经历的是令人不满意的。
IDEA, Eclipse and Netbeans are using OSGi for component assembly. IDEA,Eclipse和Netbeans正在使用OSGi进行组件组装。
It looks to me as if individual plug-ins or simple build packages are including their own Groovy package. 它看起来好像个别插件或简单构建包包含他们自己的Groovy包。
That can be a good thing for something that isn't meant to interact with projects or developers. 对于不打算与项目或开发人员交互的东西,这可能是一件好事。
From my perspective I think it would be better if Groovy was a First Class language. 从我的角度来看,我认为如果Groovy是一流语言会更好。 So there is ONLY ONE Groovy version working at any particular time. 所以只有一个Groovy版本在任何特定时间工作。
So that groovy based tooling like (say) Gradle, Spock and Groovy scripting are ALL the SAME Groovy run-time, same AST and on and on. 因此,像Gradle,Spock和Groovy脚本一样的基于groovy的工具都是SAME Groovy运行时,同样的AST和不断。
Hopefully the Stackoverflow collective have enough insight to identify methods to get things happening better. 希望Stackoverflow集体有足够的洞察力来确定更好地发生事情的方法。
On your project node, right click and choose Properties from the menu. 在项目节点上,右键单击并从菜单中选择“属性”。 Choose the Libraries category. 选择“库”类别。 In the Compile tab, you'll see under Compile-time Libraries: "Groovy 2.1.7". 在Compile选项卡中,您将在Compile-time Libraries下看到:“Groovy 2.1.7”。 Select it, and click "Edit". 选择它,然后单击“编辑”。 In the Classath tab, you'll see under Library Classpath that it refers to a groovy-all.jar under the NetBeans installation directory. 在Classath选项卡中,您将在Library Classpath下看到它引用NetBeans安装目录下的groovy-all.jar。
In my preferred groovy installation at /usr/share/groovy, I found an alternative jar file at embeddable/groovy-all.jar. 在/ usr / share / groovy的首选groovy安装中,我在embeddable / groovy-all.jar中找到了另一个jar文件。 By removing the existing Library Classpath and replacing it with this one, you can compile your project to using Groovy 2.4.12. 通过删除现有的库类路径并将其替换为此类,您可以使用Groovy 2.4.12编译项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.