如何优雅地构建项目的选定部分 [英] How to elegantly build selected parts of a project
问题描述
gradle build
我有一个项目,我最好能够写这样的东西:
或
gradle build -Pparts = part1,part5
其中第一个命令使用核心部分构建整个项目,所有其他部分。第二个命令构建核心部分,并有选择地part1和part5。
我最终将其分解为子项目并将其配置为root build.gradle,如下所示:
https://gist.github.com/Homyk/2d1d50b4678203817eaf
我现在可以做$ /
$ $ $ $ $ $ $ $ $
$ / code $ <$ $ p
或
gradle pack -Pparts = part1,part5
这很好,但至少有两个问题我想解决:
- 我必须编写一个编写命令而不是gradle build,这是我关心的,因为它是开源的,我应该没有必要解释。
- Eclipse中的子项目至少从Eclipse构建它非常麻烦,即使在运行gradle eclipse时也能有效地开发。我最终将每个子项目导入为一个非常糟糕的项目。
如果我要从头开始再次解决这个问题,最优雅的解决方案是什么?
考虑到你描述的内容,我肯定会去做一个多项目设置,这解决了问题一因为有默认方式只能调用某些子项目。有关多项目构建的更多信息,请参见此处和更具体的StackOverflow问题有关执行子项目任务的信息,请参阅此处。
我不认识你在问题二中描述的问题。在Eclipse中安装 Gradle Integration 后,Eclipse中的集成工作得很好来自Springsource的插件(尽管我有一些JUnit问题)。安装Eclipse插件后,只需执行以下操作以导入项目: $ c>插件添加到您的Gradle构建文件中。 I have a project where I ideally wanted to be able to write something like this: or Where the first command builds the whole project with a core part and all other parts. The second command builds the core part and selectively part1 and part5. What I ended up with was splitting it up into subprojects and configuring them in the root build.gradle like this:
https://gist.github.com/Homyk/2d1d50b4678203817eaf I can now do or Which is fine but there are two problems at least that I would like to have solved: If I would solve this problem again starting from scratch what would the most elegant solution be? Considering what you describe I would definitely go for a multi project set-up, this solves problem one as there are default ways to call only certain subprojects. More about multi-project build can be found here and a more specific StackOverflow question about executing tasks of subprojects can be found here. I do not recognize the issues you describe in problem two. The integration in Eclipse works just fine after I installed the Gradle Integration for Eclipse Eclipse plugin from Springsource (although I have some JUnit issues). After you installed the Eclipse plugin just do the following to import the projects:
这篇关于如何优雅地构建项目的选定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
文件 - >导入...
Gradle Project
作为导入源(位于Gradle类别下) 。
构建模型
。这应该显示根项目和它的子项目。选择您想要导入的项目(可能全部)。指定您的导入选项(我选择除使用层次结构项目名称选项之外的所有内容)。可选将项目添加到工作集。点击完成
。该项目应该已被正确导入。
gradle build
gradle build -Pparts=part1,part5
gradle pack
gradle pack -Pparts=part1,part5
eclipse
plugin to your Gradle build files.File -> Import...
Gradle Project
as import source (located under the 'Gradle' category).Build Model
. This should display the root project and it's subprojects. Select which project you want to import (probably all). Specify your 'Import Options' (I select everything except of the 'Use hierarchical project names'-option). Optionally add the projects to a working set. Than click Finish
. The project should have been correctly imported.