EAR project 3rd party dependencies

buildship
eclipse

(Cary Clark) #1

We’re moving to Gradle run by Jenkins for our server deploys so I thought I’d try to use the integration in Eclipse so that I can specify the dependencies 1 time and all build chains would use those.

I am running BuildShip 2.2.1.v20180125-1437 on Eclipse v4.6.1. I have used several versions of Gradle from 4.1 through 4.6 from inside Eclipse.

I have an EAR project whose root should contain several jar’s and war’s built from our sources. The lib directory should contain 3rd party jar’s common to some of the jar’s and the war’s. Our modules are specified using the deploy config and the 3rd party jar’s are specified via earlib’s, e.g.:

dependencies {
    earlib libraries.commons
...
    deploy project(path: ':stafftrack_war_applicant', configuration: 'archives')
...
}

libraries.commons is defined in the root project’s subprojects.ext

When I run the ear project’s Gradle -> Refresh Gradle project, the .settings/org.eclipse.wst.common.component is not changed. I’ve read many forum posts here (including https://discuss.gradle.org/t/eclipse-wtp-ear-with-3rd-party-libs/20673/8), SO, and anywhere else I could find to try to find out why not. I believe that I am not supposed to have the java plugin applied, but am supposed to apply ear and eclipse-wtp. So, I have this extremely simple build.gradle:

apply plugin: 'ear'
apply plugin: 'eclipse-wtp'

eclipse {
	wtp {
		component {
			file {
				println "Project $project.name eclipse.wtp.component.file configuration..."
				whenMerged { comp ->
					println "Project $project.name eclipse.wtp.component.file.whenMerged..." + comp
				}
			}
		}
	}
}
dependencies { ...  a boat load of 3rd party jar's and our own jar's & war's ...}

My questions:

  1. Is this the correct way to get the 3rd party jar’s deployed to my local app server (JBoss 7.1)? Previously, we’d simply put (and always had to update) them in the EAR project’s lib directory manually. I prefer not to do it this way any longer since we have the dependencies defined in build.gradle files.

  2. Isn’t the whenMerged closure supposed to run? It does not. The only output is
    Project stafftrack_ear eclipse.wtp.component.file configuration…from the configuration phase. It and withXml are run from the CLI (though the paths to the jar’s are absolute when done this way), but I believe I’ve seen posts that say withXml won’t run because of the xml <–> project model differences.

Am I misunderstanding or simply missing something?

Thanks,
Cary


(Donát Csikós) #2

Buildship calls the eclipseWtp task for web projects (e.g. projects with org.eclipse.wst.common.modulecore.ModuleCoreNature nature). so the wtp.component.file.whenMerged block should be executed upon synchronization.

However, you should not rely on that. There are two ways to declare deployment paths. It can be either specified in the component file, or in the .classpath file with the org.eclipse.jst.component.dependency attribute. Buildship automatically adds those attributes based on the Gradle synchronization. The only documentation I can give you is the Tooling API integration tests. It’s pretty readably imho, please have a look: https://github.com/gradle/gradle/blob/a0307889bed8a9ce58e1faf005a86ad86e1fb99e/subprojects/ide/src/crossVersionTest/groovy/org/gradle/plugins/ide/tooling/r214/ToolingApiEclipseModelWtpClasspathAttributesCrossVersionSpec.groovy#L198