Skip to content

Instantly share code, notes, and snippets.

@willmenn
Last active August 17, 2018 18:39
Show Gist options
  • Save willmenn/e9f6b244fc38d6d0ea4e6f1b3f6084f7 to your computer and use it in GitHub Desktop.
Save willmenn/e9f6b244fc38d6d0ea4e6f1b3f6084f7 to your computer and use it in GitHub Desktop.
Intellij configuration to be used by gradle idea pllugin

To use this configuration you will need to have the idea gradle plugin installed on your build.gradle and import this file.

This file will add in your project the following configuration:

  • Enable annotation process <- for Lombok
  • Enable Gradle Auto-Import
  • Enable optmize imports
  • Configure Spring plugin
  • Enable Intellij to create Empty Content Root Dirs for Gradle (create directories for empty content roots automatically)

Action needed:

  • In order to make the Spring plugin to work you will need to update the Application.java path from your on project.
apply plugin: 'idea'
final CODE_STYLE_COMPONENT_TEXT = '''
<component name='ProjectCodeStyleSettingsManager'>
<option name='PER_PROJECT_SETTINGS'>
<value>
<option name='CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND' value='999' />
<option name='NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND' value='999' />
</value>
</option>
<option name='USE_PER_PROJECT_SETTINGS' value='true' />
</component>
'''
final CODE_SYTLE_COMPONENT_NODE = new XmlParser().parseText(CODE_STYLE_COMPONENT_TEXT)
final OPTIMIZE_IMPORTS = '''
<component name="CodeInsightWorkspaceSettings">
<option name="optimizeImportsOnTheFly" value="true" />
</component>
'''
final OPTIMIZE_IMPORTS_NODE = new XmlParser().parseText(OPTIMIZE_IMPORTS)
final GRADLE_SETTINGS = '''
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#JAVA_HOME" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
<option name="useAutoImport" value="true" />
<option name="createEmptyContentRootDirectories" value="true" />
</GradleProjectSettings>
</option>
</component>
'''
final GRADLE_SETTINGS_NODE = new XmlParser().parseText(GRADLE_SETTINGS)
idea {
project {
ipr.withXml {
def node = it.asNode()
//enables git mapping
def vcsConfig = node.component.find { it.'@name' == 'VcsDirectoryMappings' }
vcsConfig.mapping[0].'@vcs' = 'Git'
vcsConfig.mapping[0].'@directory' = '$PROJECT_DIR$'
node.append(OPTIMIZE_IMPORTS_NODE)
node.append(CODE_SYTLE_COMPONENT_NODE)
node.append(GRADLE_SETTINGS_NODE)
//enables annotation processing. Needed for Lombok.
def compilerConfig = node.component.find { it.'@name' == 'CompilerConfiguration' }
def annotationProcessingBlock = compilerConfig.annotationProcessing[0]
annotationProcessingBlock.appendNode('profile', [default: 'true', name: 'Default', enabled: 'true'])
}
}
module {
iml.withXml {
def node = it.asNode()
def facetManager = node.appendNode('component', [name: 'FacetManager']);
def builder = new NodeBuilder();
//adds spring facet configuration
def springFacetBuilder = builder.facet(type: "Spring", name: 'Spring') {
configuration {
fileset(id: 'fileset', name: 'Spring Application Context', removed: 'false')
}
}
facetManager.append springFacetBuilder
def springFacet = facetManager.facet.find { it.@name == 'Spring' }
def springFacetFiles = springFacet.configuration.fileset[0]
springFacetFiles.appendNode('file', 'file://$MODULE_DIR$/src/main/java/Application.java')
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment