In the end, I went with the offer of homeland above and used the idea plugin. It turns out that I did not configure it correctly the first time I tried it (I applied only the plugin to the main project, not the subprojects).
I only found out about this after writing my own task of updating dependencies for an IntelliJ project (based on the project structure of the .idea catalog layout). I am going to use the plugin as there will be less maintenance, but here is my solution for posterity if it is useful to anyone:
ext { intelliJLibraryDir = "$gradle.rootProject.rootDir/.idea/libraries" userHomeDir = gradle.gradleUserHomeDir.parent } task cleanIntelliJLibraries << { ant.delete (includeEmptyDirs: 'true') { fileset(dir: intelliJLibraryDir, includes: '*.xml') } } task createIntelliJLibraries(dependsOn: cleanIntelliJLibraries) << { // The unique set of dependency artifacts across all subprojects def uniqueProjectArtifacts = subprojects.collectMany { if (it.configurations.compile) { it.configurations.compile.resolvedConfiguration.resolvedArtifacts.findAll { it.moduleVersion.id.group != "my.project" } } else { [] } }.unique() // Output a library xml file for each of the dependency artifacts uniqueProjectArtifacts.each { artifact -> def artifactPath = artifact.file.path def artifactName = artifact.moduleVersion.id.with { "$group:$name:$version" } def intelliJLibraryPath = artifactPath.replace(userHomeDir, '$USER_HOME$') def intelliJLibraryFileName = "Gradle__$artifactName".replace(':', '_').replace('.','_') + ".xml" new File("$intelliJLibraryDir/$intelliJLibraryFileName").withWriter { writer -> def dependencyXML = new MarkupBuilder( writer ) dependencyXML.component (name: "libraryTable") { library (name: "Gradle: $artifactName") { CLASSES { root (url: "jar://$intelliJLibraryPath!/") } JAVADOC {} SOURCES {} } } } } } task updateIntelliJModules(dependsOn: createIntelliJLibraries) << { subprojects.each { project -> def root = new XmlSlurper().parse(new File("${project.name}.iml")) // Remove the existing dependencies root.component.orderEntry.findAll { it.@type == "library" && it.@level == "project" }.replaceNode {} // Add in the new dependencies if (project.configurations.compile) { project.configurations.compile.resolvedConfiguration.resolvedArtifacts.findAll { it.moduleVersion.id.group != "my.project" }.each { artifact -> def artifactName = artifact.moduleVersion.id.with { "Gradle: $group:$name:$version" } root.component.appendNode { orderEntry (type: "library", exported: "", name: artifactName, level: "project") } } } def outputBuilder = new StreamingMarkupBuilder() new File("${project.name}.iml").withWriter { writer -> groovy.xml.XmlUtil.serialize(outputBuilder.bind{ mkp.yield root }, writer) } } }
Chris priority
source share