Add library project to Deployment Assembly

In Eclipse I have the main “Dynamic Web Project” that depends on a “Java Project” library.
When not using Gradle I would add the library project to the “Deployment Assembly” of the main project, with the final result of having the library deployed to the server as a jar inside of WEB-INF/lib.

I currently have both projects as independent Gradle builds. If I manually change the Deployment Assembly of the main project, it gets overwritten at every “Refresh Gradle Project”. So I guess there must be some way to do that automatically.

  • Is there some “eclipse-wtp” option to specify the content of the Deployment Assembly?

  • Should I configure a multiproject gradle build? In such a case, can I keep the library project as an external independent project or do I need a common root folder for both projects?

  • Should I use the “Composite Builds” feature instead? Is it supported by Buildship already?

This would be a use case for composite builds, but WTP is currently not supported for composites. This will be improved within the first half of this year.

If these two projects really belong together (i.e. same repository, same release cycle), then putting them both in the same multi-project build would be the way to go.

If they should remain separate, then you can work around this problem for now by manually configuring the deployment assembly in your Gradle build to point to the project dependency instead of the binary dependency. More specifically, you can modify the final model using eclipse.wtp.component.file.whenMerged {}.

I don’t understand what you say about whenMerged, but I found that a multi-project build with flat layout apparently does the trick:

  • the Java Project library “MyLib” has no notion of multi-projects: the settings.gradle is empty

  • the Dynamic Web Project “MyWebApp” has a settings.gradle with

    rootProject.name = ‘MyWebApp’
    include ‘MyLib’
    project(’:MyLib’).projectDir = “…/…/my-lib/MyLib” as File

  • “MyWebApp” also has a build.gradle with

    compile project(‘MyLib’)

Now I can correctly build from gradle and have the dependency inserted in the “Deployment Assembly” by “Refresh Gradle Project”.

If you use ‘include’, you are saying that the lib is a subproject of app. This only makes sense if it is in the same repository. It shouldn’t be built by itself at all then. You might want to move both under a common root if this was your intention.

My intention was to keep them totally separate and independent, because the lib could be used in many other projects.
They could be in different git repositories.
I know that using a path like “…/…/my-lib/MyLib” is bad because it assumes that both projects have been checked out in the same base location (the root of the local git on the developer pc) but I guess this is what will usually happen.
And it saves me from understanding the “whenMerged” thing :blush:

Make sure to follow the Buildship releases. Once composite builds support WTP, you can make the separate again and use a conditional includeBuild instead. :slight_smile: