Leaving out dependencies when generating EAR

Hi all,

I just found the following question and @st_oehme’s reply.

(and no, that was a different StefanM asking ;-))

I totally agree with the reply, especially that the consumer of a library is responsible for knowing whether a dependency is already provided at runtime. Now my question is: What if the consumer is the EAR plugin? In the Enterprise Java world there are various dependencies hat must not be included in the EAR. How can I declare a subproject’s dependencies using implementation and then let the EAR plugin decide whether to include that dependency or not?

Update
I just realize that this question doesn’t make much sense without the following information:
We have a larger project with an EAR composed of many JARs generated by subprojects. We want to keep the effort for developers in subprojects as small as possible, so the subproject developer shall not have to modify the earlib dependencies of the EAR project (especially since we have multiple EAR projects putting together different sets of subprojects). Therefore, we do this

// Add all modules from ejbProjects and add dependencies into lib folder - make sure that ejbProjects are not added to the lib, too.
ejbProjects.forEach { ejbProject: String ->
    deploy(project(ejbProject))
    earlib(project(ejbProject, "default")) {
        ejbProjects.forEach {
            exclude(module = it)
        }
    }
}

based on a list of ejbProjects defined in the EAR project.