Created
January 5, 2013 04:48
-
-
Save fitzyyf/4459817 to your computer and use it in GitHub Desktop.
Gradle create Idea Engineering Web facet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Helper methods to get the directory in which to deploy webapps (add-ons). | |
File getDeployLoc() { | |
file("$buildDir/"+war.baseName.toLowerCase()) | |
} | |
idea { | |
project { | |
//if you want to set specific jdk and language level | |
rootProject.afterEvaluate { | |
jdkName = "${rootProject.sourceCompatibility}" | |
languageLevel = "${rootProject.sourceCompatibility}" | |
} | |
ipr.withXml { | |
def node = it.asNode() | |
def vcsConfig = node.component.find { it.'@name' == 'VcsDirectoryMappings' } | |
vcsConfig.mapping[0].'@vcs' = 'Git' | |
def mgrNode = node.component.find { it.'@name' == 'ArtifactManager' } | |
if (!mgrNode) | |
mgrNode = node.appendNode('component', [name: 'ArtifactManager']) | |
def webNode = mgrNode?.artifact.find { it.'@name' == 'Web exploded' } | |
if (webNode) | |
mgrNode.remove(webNode) | |
mgrNode.append(new XmlParser().parseText(""" | |
<artifact type="exploded-war" build-on-make="true" name="Web exploded"> | |
<output-path>${pathFactory.relativePath('PROJECT_DIR', getDeployLoc()).relPath}</output-path> | |
<root id="root"> | |
<element id="javaee-facet-resources" facet="${war.baseName}/web/Web" /> | |
<element id="directory" name="WEB-INF"> | |
<element id="directory" name="classes"> | |
<element id="module-output" name="${war.baseName.toLowerCase()}" /> | |
</element> | |
<element id="directory" name="lib" /> | |
</element> | |
</root> | |
</artifact> | |
""")) | |
def libNode = mgrNode.artifact.root.element.find { it.'@name' == 'WEB-INF' }.element.find { it.'@name' == 'lib' } | |
def userHome = new File(System.getProperty("user.home")) | |
modules[0].resolveDependencies().each { dep -> | |
if (dep instanceof org.gradle.plugins.ide.idea.model.ModuleLibrary) | |
{ | |
if (dep.scope == 'COMPILE' || dep.scope == 'RUNTIME') | |
dep.classes.each { | |
libNode.appendNode('element', [id: 'file-copy', path: pathFactory.relativePath(userHome, '$USER_HOME$', it.file).relPath]) | |
} | |
} | |
} | |
} | |
} | |
module { | |
scopes.PROVIDED.plus += configurations.providedCompile | |
scopes.PROVIDED.plus += configurations.providedRuntime | |
scopes.COMPILE.minus += configurations.providedCompile | |
scopes.RUNTIME.minus += configurations.providedRuntime | |
inheritOutputDirs = false | |
outputDir = file("$buildDir/classes/main") | |
testOutputDir = file("$buildDir/classes/test") | |
iml.withXml { | |
def node = it.asNode() | |
def mgrNode = node.component.find { it.'@name' == 'FacetManager' } | |
if (!mgrNode) | |
mgrNode = node.appendNode('component', [name: 'FacetManager']) | |
def webNode = mgrNode?.facet.find { it.'@name' == 'Web' } | |
if (webNode) | |
mgrNode.remove(webNode) | |
mgrNode.append(new XmlParser().parseText(''' | |
<facet type="web" name="Web"> | |
<configuration> | |
<descriptors> | |
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml"/> | |
</descriptors> | |
<webroots> | |
<root url="file://$MODULE_DIR$/src/main/webapp" relative="/"/> | |
</webroots> | |
<sourceRoots> | |
<root url="file://$MODULE_DIR$/src/main/resources"/> | |
<root url="file://$MODULE_DIR$/src/main/java"/> | |
</sourceRoots> | |
</configuration> | |
</facet> | |
''')) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment