Intellij Idea plugin xml modifications dissapear when intellij loads

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.

From my experience, it usually means that something is wrong with the XML. How did you open the project in IntelliJ?

I open the project using the ipr file directly. The iml shows the change for a moment, however after a few seconds it disappears.

I open the project using the ipr file directly. The iml shows the change for a moment, however after a few seconds it disappears.

Most likely the XML is not correct, or the schema has changed. You may want to ask in the IntelliJ forums.

After doing a file compare with my gradle output and the intellij output i determined that the deploymentDescriptor node had a ‘relativePath’ element that was meant to be just ‘relative’. when i corrected this the setting correctly persisted.

Is there an XSD file for the ipr, iws and iml files? or bar that, is there any comprehensive reference of these files on a technical level?

P.S. Thank you for the swift reply to my question!

Is there an XSD file for the ipr, iws and iml files? or bar that, is there any comprehensive reference of these files on a technical level?

I’m not aware of such a thing, but the IntelliJ folks will know better.