如何优雅地构建项目的选定部分 [英] How to elegantly build selected parts of a project

查看:95
本文介绍了如何优雅地构建项目的选定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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 

这很好,但至少有两个问题我想解决:


  1. 我必须编写一个编写命令而不是gradle build,这是我关心的,因为它是开源的,我应该没有必要解释。

  2. Eclipse中的子项目至少从Eclipse构建它非常麻烦,即使在运行gradle eclipse时也能有效地开发。我最终将每个子项目导入为一个非常糟糕的项目。

如果我要从头开始再次解决这个问题,最优雅的解决方案是什么?

解决方案

考虑到你描述的内容,我肯定会去做一个多项目设置,这解决了问题一因为有默认方式只能调用某些子项目。有关多项目构建的更多信息,请参见此处和更具体的StackOverflow问题有关执行子项目任务的信息,请参阅此处



我不认识你在问题二中描述的问题。在Eclipse中安装 Gradle Integration 后,Eclipse中的集成工作得很好来自Springsource的插件(尽管我有一些JUnit问题)。安装Eclipse插件后,只需执行以下操作以导入项目: $ c>插件添加到您的Gradle构建文件中。

  • 在Eclipse中打开导入对话框。通过点击文件 - >导入...

  • 选择 Gradle Project 作为导入源(位于Gradle类别下) 。
  • 导入Gradle项目对话框将会被忽略。选择根项目所在的文件夹作为根文件夹。点击构建模型。这应该显示根项目和它的子项目。选择您想要导入的项目(可能全部)。指定您的导入选项(我选择除使用层次结构项目名称选项之外的所有内容)。可选将项目添加到工作集。点击完成。该项目应该已被正确导入。


  • I have a project where I ideally wanted to be able to write something like this:

    gradle build
    

    or

    gradle build -Pparts=part1,part5
    

    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

    gradle pack
    

    or

    gradle pack -Pparts=part1,part5
    

    Which is fine but there are two problems at least that I would like to have solved:

    1. I have to write a made up command instead of gradle build, which I care about because it`s open source, and I should not have to explain that.
    2. With subprojects in Eclipse at least it`s very cumbersome to get it to build from Eclipse and develop effectively even when running 'gradle eclipse'. I ended up importing each subproject as a project which is pretty awful.

    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:

    1. Apply the eclipse plugin to your Gradle build files.
    2. In Eclipse open the 'Import' dialog by opening. By clicking File -> Import...
    3. Choose Gradle Project as import source (located under the 'Gradle' category).
    4. The 'Import Gradle Project' dialog will pup-up. Select the folder the root project is located in as root folder. Click 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.

    这篇关于如何优雅地构建项目的选定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆