I am trying to create auto generated idea project files for my modules and want to add a web facet to all projects with the WarPlugin.
This is my code below:
subprojects { p ->
plugins.withType(WarPlugin) {
idea {
module {
iml {
withXml { provider ->
def node = provider.asNode();
// Initialize the facet manager
def facetManager = node.component.find {
it.’@name’ == ‘FacetManager’
}
if (!facetManager) {
facetManager = node.appendNode(‘component’, [name: ‘FacetManager’])
}
// Create the web facet
def webFacet = facetManager.facet.find { it.’@type’ == ‘web’ }
if (webFacet) {
facetManager.remove(webFacet)
}
webFacet = facetManager.appendNode(‘facet’, [name: ‘Web’, type: ‘web’])
def configuration = webFacet.appendNode(‘configuration’)
logger.lifecycle “properties: ${properties}”
def webXml = p.war.webXml
if (!webXml) webXml = ‘WEB-INF/web.xml’
def descriptors = configuration.appendNode(‘descriptors’)
descriptors.appendNode(‘deploymentDescriptor’, [name: ‘web.xml’, url: “file://$MODULE_DIR$/${p.relativePath(webXml).replaceAll(’\\’, ‘/’)}”])
def webAppDir = p.webAppDir
def webRoots = configuration.appendNode(‘webroots’)
webRoots.appendNode(‘root’, [url: “file://\$MODULE_DIR\$/${p.relativePath(webAppDir).replaceAll(’\\\\’, ‘/’)}”, relativePath: ‘/’])
}
}
}
}
}
}
This produces the correct xml as i have cross referenced it with the xml intellij produces when i create the facet through the ide. however this xml is overridden by intellij as soon as i load the module settings. Is there something wrong with my code or can i not add facets in this manner.