0

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?

Homyk
  • 364
  • 2
  • 7

1 Answers1

1

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.
Community
  • 1
  • 1
HELOX
  • 529
  • 2
  • 13
  • Thank you, I was not aware of the Gradle Eclipse plugin; that made things easy to setup and the test project worked as expected. I also learned that I can build subprojects selectively, but I want the class files to be output to a jar based on that selection, this is what the pack command does. Are there any default ways of doing this? – Homyk Jun 11 '15 at 17:26
  • I'm glad my answer helped you, if this answered your question please accept it as your question about selectively building subproject should be concidered a new question. Regarding that question: if your subprojects are Java/Groovy project running the `gradle build` command of a specific subproject should, if configured correctly, output one or more artifacts (jars, ears, wars, etc.) with in them exactly the classes of the subproject. I concider that the default. – HELOX Jun 12 '15 at 07:13
  • @Homyk Have you had any luck with this yet? – HELOX Jun 15 '15 at 06:40