Showing posts with label buildship. Show all posts
Showing posts with label buildship. Show all posts

Wednesday, September 27, 2017

How to allow / workaround nested composite Gradle builds

Leave a Comment

I'm running into the same issue as reported here:

I have a Java project A which depends on project B (module), and project B dependes on project C (another module). For project A I would like to setup "includeBuild ../projectB" and for project B I would like too setup "includeBuild ../projectC" so that I could develop everything in Eclipse + Buildship 2.0 without the need to run Gradle for every small change in each of the projecta A, B and C.

But if I setup this I get: "Included build '%s' cannot have included builds.".

Expected Behavior

Recursive "includeBuild" would recursively include dependent projects.

Current Behavior

I get "Included build '%s' cannot have included builds.".

Your Environment

Gradle 3.5, Buildship 2.0, Eclipse 3.6

How can I resolve / work around this issue? In my instance, I have utility project that includes email functionality (using JavaMail). The email functionality is needed in the data project and a UI project. The UI project also depends on the data project.

2 Answers

Answers 1

Have you considered

  1. Ensuring that none of the individual builds are composite builds
  2. Having an "uber" build which is a composite of everything

Note that the settings.gradle is itself a groovy script, so you could create a dynamic composite, eg all sub-folders with a build.gradle under a parent.

uber/settings.gradle

new File("c:/someFolder").listFiles().each { File f ->     if (f.directory && new File(f, 'build.gradle').exists()) {         includeBuild f     } } 

Eg

c:/someFolder/project1/build.gradle c:/someFolder/project1/src/main/java/**/*.java c:/someFolder/project2/build.gradle c:/someFolder/project2/src/main/java/**/*.java c:/uber/settings.gradle (as above) 

Answers 2

Adding another answer for a different approach...

Each settings.gradle could add a check to before includeBuild to see if it's already inside a composite. If it's already inside a composite, it doesn't includeBuild.

See here for extra info on the composite check

Eg

project2/settings.gradle

boolean inComposite = gradle.parent != null if (!inComposite) {     includeBuild '../project1' } 

project3/settings.gradle

boolean inComposite = gradle.parent != null if (!inComposite) {     includeBuild '../project1'     includeBuild '../project2' } 

project4/settings.gradle

boolean inComposite = gradle.parent != null if (!inComposite) {     includeBuild '../project1'     includeBuild '../project2'     includeBuild '../project3' } 

etc etc

Using this approach you could run gradle from wherever you like and it should behave as expected (ie substitute dependencies with local projects)

Read More

Thursday, April 28, 2016

How to limit BuildShip (gradle eclipse) integrated functionality?

Leave a Comment

Now that I am using gradle for all of my new development, I'm running into issues with BuildShip features I really don't want.

For instance, when I hit the Run hotkey when I have a unit test open in Eclipse, I only want it to run as a JUnit test, alone. But Gradle has inserted its own hooks and option, which means extra clicking or keypresses beyond the one-stroke hotkey I have assigned to Run that I can tell it I want JUnit. (The gradle test option actually runs all tests, which takes minutes.).

Question: Is there a way to remove this hook in gradle without diving into the source code and ripping out functionality myself?

This isn't the only interference (interfering with run last is another), but it's my #1 annoyance about BuildShip.

"run as"

Essentially, I want this popup to stop happening.

1 Answers

Answers 1

Indeed you cannot change the available launchers prompt but you can change the default hotkeys related to each launcher and directly use the one you prefer.

From Windows > Preferences > General > Editor > Keys you can get the list of available hot-key mappings. Filter the (long) list by typing test as show below:

enter image description here

As you can see you have several mappings for running JUnit tests: Gradle, JUnit runner, Maven.

The default configuration for JUnit runner is Alt+Shift+X,T, not really user friendly I would say.

I changed it to a more concise Alt+U down in the Binding option and applied the changes. Now you can run any JUnit test on its open editor windows without any prompt, simply type Alt+U and the JUnit runner will be triggered automatically for that single unit test.

Read More