Java项目构建
我有一些与 Java 项目构建相关的问题。
当试图找到一些使用 Gradle
作为构建系统的项目的好示例时,我通过 Google Code
进行搜索。
有一些,我尝试查看这个项目并检查相关的 build.gradle
文件:http://code.google.com/p/spock/source/browse/trunk/spock-example/build.gradle?r=1316
现在,我可以使用命令行轻松构建这个项目,并且所有依赖项都可以很好地自动解决。但是,自动构建还会生成一个 IntelliJ IDEA
项目。
所以,问题。
我确信网络上有很多基于 Gradle
的项目。这些构建系统(例如 Gradle
)如何与 IDE
集成?
例如,为 IntelliJ IDEA
生成的项目无法使用 IDE
的内部工具进行编译,也无法调试(!)
我唯一能做的就是扩展测试用例、运行它们并打包最终的 jar。 这样可以吗?我不太习惯 Java 构建系统,但我认为它们应该可以轻松地与 IDE
集成。
使用 Ant
/< 制作相同的东西怎么样?代码>Maven?
我可能遗漏了一些东西,如果有人有经验,请帮助我:)
谢谢。
I have some question related to project building in Java
.
When attempting to find some good examples of projects using Gradle
as their building system, I was searching through Google Code
.
There were some and I tried checking out this project and examined the related build.gradle
file: http://code.google.com/p/spock/source/browse/trunk/spock-example/build.gradle?r=1316
Now, I can easily build this project using command line and all the dependencies are nicely and automatically resolved. However, automatic build also generates an IntelliJ IDEA
project.
So, the question.
I'm sure there are plenty of Gradle
-based projects on the web. How are these building systems like Gradle
being integrated with IDE
's?
For example, generated project for IntelliJ IDEA
can't be compiled using the internal tools of the IDE
and can't be debugged (!)
The only thing I can do is extend the test cases, run them and package the final jar. Is this OK? I'm not really used to Java building systems, but I thought they should integrate easily with the IDE
.
What about making the same things with Ant
/Maven
?
I'm probably missing something and if somebody has experience, please help me :)
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(3)
我强烈建议您查看Maven
。 Maven 不依赖于任何特定的 IDE,尽管我可以想象可以为您的 IDE 找到它的插件,但它具有对 Eclipse 的插件支持。
Maven 是最有前途的构建之一,它的作用不仅仅是实际构建。它是持续集成构建系统的关键推动者,即 hudson + maven + Continum + ...
它具有依赖性管理,这样您就可以指定您希望使用的外部库,并且它透明地下载并链接到您的构建,两者在编译和构建期间。
它具有正在采用的“标准”包装实践,并且非常理智和简单。
总的来说,我最近看到了更多使用 Maven 启动的项目,该项目本身是 Apache 的一部分,并且非常活跃。
Maven 无法与 ant 进行比较,就像 Maven vs Ant 中那样,Maven 比 Ant 不仅仅是一个构建脚本。通过插件使用 Maven 可以实现很多功能(例如 Maven Cargo 插件,它简化了应用程序服务器的部署)。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
据我所知,Gradle 对 IntelliJ 的支持已接近完成。我已成功使用它为一个相当复杂的项目生成 IntelliJ 项目配置。我没有机会太多地使用它,因为我只是考虑从 Gradle 过渡到 Maven,但我没有注意到任何像你描述的问题。也许您正在使用的构建使用的是旧版本的 Gradle,尚未提供良好的 IDE 支持?您能举一些具体的例子来说明那些不按您预期方式工作的事情吗?
编辑:专门针对您的问题,我这样做了,它在 Windows 7 上与 Gradle 1.0-milestone-4、IntelliJ 10.5 和 JDK 1.6.0_26 一起工作:
然后,在 IntelliJ 中,文件 ->打开项目...,导航到并选择 .../spock/spock.ipr 作为要打开的项目。我首先运行了项目的完整构建(Build -> Make Project),并遇到了 spock.util.concurrent.BlockingVariables 的问题。我必须告诉 IntelliJ 不要为该类生成存根。我的 Groovy 不是很强大,所以我无法告诉您为什么它解决了问题或者这样做的含义是什么。之后,我能够成功运行 spock-spring/src/test/groovy/org/spockframework/spring/InjectionExamples.groovy。然后我在该文件的第 38 行 (
service instanceof IService1
) 上放置了一个断点,然后我能够对其进行调试并在该行上中断。值得注意的是,Gradle 构建并不包含该项目中的所有模块。默认的 Maven 构建总共包含 10 个模块,而 Gradle 构建只有 6 个。 Gradle 构建不包括 spock-maven、spock-example、spock-grails-support 或 spock-grails。如果我不得不猜测的话,他们可能会分阶段过渡到 Gradle,但还没有完全实现。
To my knowledge, Gradle's IntelliJ support is nearly complete. I've successfully used it to generate an IntelliJ project configuration for a fairly complex project. I haven't had a chance to use it much, as I'm just looking at transitioning from Gradle to Maven, but I didn't notice any problem like you seem to be describing. Maybe the build you're using is using an older version of Gradle that didn't have good IDE support yet? Can you give some specific examples of things that don't work the way you expect?
Edit: Specifically for your problem, I did this, and it worked with Gradle 1.0-milestone-4, IntelliJ 10.5, and JDK 1.6.0_26 on Windows 7:
Then, in IntelliJ, File -> Open Project..., navigate to and select .../spock/spock.ipr as the project to open. I first ran a full build of the project (Build -> Make Project), and hit a problem with spock.util.concurrent.BlockingVariables. I had to tell IntelliJ not to generate a stub for that class. My Groovy isn't very strong, so I can't tell you why that fixed the problem or what the implications of doing it are. After that, I was able to successfully run spock-spring/src/test/groovy/org/spockframework/spring/InjectionExamples.groovy. Then I put a breakpoint on line 38 of that file (
service instanceof IService1
), and I was able to debug it and break on that line.It's worth noting that the Gradle build doesn't include all of the modules in that project. The default Maven build includes ten modules in total, whereas the Gradle build only has six. The Gradle build doesn't include spock-maven, spock-example, spock-grails-support, or spock-grails. If I had to guess, they're probably transitioning to Gradle in phases, and they're not all the way there yet.