Homyk
Homyk

Reputation: 364

How to elegantly build selected parts of a project

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?

Upvotes: 0

Views: 199

Answers (1)

HELOX
HELOX

Reputation: 529

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.

Upvotes: 1

Related Questions