Configure ear project in eclipse

eclipse

(Ralf) #1

I’m trying to configure an EAR-project with buildship but I fail to specify the version and some other settings.
The biggest headache for me at the moment is the file
.settings\org.eclipse.wst.common.project.facet.core.xml
I have the following at the moment (created by eclipse GUI):

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <runtime name="was.base.v9"/>
  <fixed facet="jst.ear"/>
  <installed facet="jst.ear" version="6.0"/>
  <installed facet="com.ibm.websphere.coexistence.ear" version="9.0"/>
  <installed facet="com.ibm.websphere.extended.ear" version="9.0"/>
</faceted-project>

After “Refresh Gradle Project” this changes to

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
	<fixed facet="jst.ear"/>
	<installed facet="jst.ear" version="5.0"/>
</faceted-project>

I’ve tryed quite a lot but propably I miss something essential.

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

ear {
	appDirName '/' // changed to match the eclipse-path (META-INF in project root) But have tryed to use 'src' and move META-INF in there as well
	deploymentDescriptor { // tryed to explicitly specify deploymentdescriptor and version as well as ommitting this
		fileName = "application.xml"
		version = "6.0"
		applicationName = "Test"
	}
  // with the following wtp-block I managed to get the correct runtime and the websphere facets. But still problems with the jst.ear version (comment below)
	/*wtp {
		facet {
			file {
				withXml {
					def node = it.asNode()
					node.appendNode('runtime', [name: 'was.base.v9'])
				}
       		}
       		
			//facet name: 'jst.ear', version: '6.0' // leads to a second entry, but the one with version 5.0 stays there :-(
			facet name: 'com.ibm.websphere.coexistence.ear', version: '9.0'
			facet name: 'com.ibm.websphere.extended.ear', version: '9.0'
		}
	}*/
}

Can anybody help me a little bit pointing me on what is the correct way to achive the desired result? I don’t believe I’m the first one who wants to set the ear-version so I propably miss something!?

Thanks for reading and trying to help :slight_smile:


(nerro) #2

hi, your eclipse configuration block is inside of ear block. I think it should be inside of eclipse block like

eclipse {
  // custom eclipse configuration
}

Take a look at https://docs.gradle.org/current/userguide/eclipse_plugin.html#wtpWithXml


(Ralf) #3

Hi,

@nerro thank you for the hint, of course this is an error but was an error I did on copy-paste and formatting in the forum here. In my build.gradle the wtp block is inside the eclipse block… Sorry for that

Back to the problem:
I found a solution to get my desired output but I’m still not sure if this is the way I should do it:

eclipse {		
	wtp {
		facet {
			file {
				withXml {
					def node = it.asNode()
					node.appendNode('runtime', [name: 'was.base.v9'])
				}
				whenMerged { 
					//the following solves the issue - but is this desired to do this way?
					facets.each { f ->
						if (f.name == 'jst.ear') {
							f.version = '6.0'
						}
					}
				}
       			}
   			//facet name: 'jst.ear', version: '6.0' // this would insert a second entry with version 6.0, version 5.0 stays there...
			facet name: 'com.ibm.websphere.coexistence.ear', version: '9.0'
			facet name: 'com.ibm.websphere.extended.ear', version: '9.0'
   		}
   	}
}

Without overwriting the version of jst.ear in the whenMerged block I always get version ‘5.0’ on Refresh Gradle Project even if I changed it by hand or eclipse dialog before. Therefore I think gradle/buildship is setting this explicitly but I have no clue where this version 5.0 comes from!?


(nerro) #4

About 5.0 version. Could be default? https://github.com/gradle/gradle/blob/master/subprojects/ide/src/main/java/org/gradle/plugins/ide/eclipse/EclipseWtpPlugin.java#L308


(Ralf) #5

:astonished: seems likely
Then I just wonder if it is appropriate in the year 2018 to use version 5.0 as a default. OK, maybe it is the most compatible one???
I think there should be a sensible discovery (maybe from deploymentdescriptor? interestingly the default version for generating a deploymentddescriptor if absent is 6…) or a possibility to configure the correct version in an obvious way.
Is this a bug? Or just not fully implemented yet?


(Ralf) #6

seems to be related with https://github.com/gradle/gradle/issues/945