Skip to content

remal-gradle-plugins/idea-settings

Repository files navigation

Tested on Java LTS versions from 8 to 21.

Tested on Gradle versions from 6.0 to 8.8-rc-1.

name.remal.idea-settings plugin

configuration cache: not supported

A Gradle plugin that allows to configure IntelliJ IDEA directly in build script.

This plugin applies org.jetbrains.gradle.plugin.idea-ext plugin and configures its extensions

Enables delegating Run/Build and Test actions to Gradle

This plugin delegates Run/Build and Test actions to Gradle.

Configures encoding of *.propertiers files based on JVM version and content of .editorconfig file

If the build doesn't use any of AbstractCompile tasks, then encoding from .editorconfig file will be used for *.properties files. If the project doesn't have .editorconfig file, or encoding is not set there, ISO-8859-1 encoding will be used by default.

For each of AbstractCompile tasks targetCompatibility property is taken. If minimum targetCompatibility is less than Java 9, then ISO-8859-1 encoding will be used for *.properties files.

If minimum targetCompatibility is equal or more than Java 9, encoding from .editorconfig file will be used for *.properties files. If the project doesn't have .editorconfig file, or encoding is not set there, UTF-8 encoding will be used by default.

Transparent native-to-ascii conversion will be enabled for all encodings except UTF-8.

Enables EditorConfig support

This plugin enables EditorConfig support.

Allows to add required plugins

To add a required plugin:

ideaSettings {
  requiredPlugins += [
    'idea.plugin.id-1',
    'idea.plugin.id-2',
  ]
}

Configure default nullability annotation

To configure default annotations IDEA uses for nullity checks, use this configuration:

ideaSettings {
  nullability {
    defaultNotNullAnnotation = 'javax.annotation.Nonnull'
    defaultNullableAnnotation = 'javax.annotation.Nullable'
  }
}

Configures Actions on Save

Native IDEA Actions on Save functionality is used.

By default, nothing is changed. If the functionality is enabled, it stays enabled. If it's disabled, it stays disabled.

To configure reformatting sources on save:

ideaSettings {
  runOnSave {
    reformatMode = 'DISABLED' // to disable automatic reformatting
    reformatMode = 'WHOLE_FILE' // to format the whole file
    reformatMode = 'CHANGED_LINES' // to format changed lines only
  }
}

To configure imports optimization on save:

ideaSettings {
  runOnSave {
    optimizeImports = false // to disable automatic imports optimization
    optimizeImports = true // to enable automatic imports optimization
  }
}

IntelliJ IDEA picks up these changes only by restarting.

Configures CheckStyle-IDEA plugin

If any of the Gradle projects uses checkstyle Gradle plugin, CheckStyle-IDEA plugin will be configured:

  • IDEA Checkstyle version will be set to the version used by Gradle build
  • Dependencies with Third-Party Checks will be configured correctly
  • Gradle project's Checkstyle XML config will be used as a config for the CheckStyle-IDEA

To configure CheckStyle-IDEA to use specific XML config:

ideaSettings {
  checkstyle {
    configFile = "path/to/xml/config/can/be/relative" // to use specific file with checks
    useBundledSunChecks() // to use bundled Sun checks
    useBundledGoogleChecks() // to use bundled Google checks

    treatErrorsAsWarnings = true // Treat errors as warnings
  }
}

Configures IDEA Ultimate default project SQL dialect

For those developers who use IntelliJ IDEA Ultimate, a default project SQL dialect can be configured:

ideaSettings {
  database {
    defaultDialect = 'PostgreSQL'
  }
}

This plugin can add default JVM parameters to IDEA's Java application run configuration and Spring Boot run configuration.

ideaSettings {
  runConfigurations {
    javaApplication {
      jvmParameters += [
        '-Xmx1G',
        '-Pspring.profiles.active=local'
      ]
    }
  }
}

Migration guide

Version 2.* to 3.*

Package name was changed from name.remal.gradleplugins.ideasettings to name.remal.gradle_plugins.idea_settings.