添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

IntelliJ IDEA 2023.2 Help

Gradle

IntelliJ IDEA supports a fully-functional integration with Gradle that helps you automate your building process. You can easily create a new Gradle project, open and sync an existing one, work with several linked projects simultaneously, and manage them.

You can also create a Gradle project and store it in the WSL environment or open it from the WSL file system. For more information, refer to the WSL section.

Create a new Gradle project

  1. Launch the New Project wizard . If no project is currently opened in IntelliJ IDEA, click New Project on the welcome screen. Otherwise, select File | New | Project from the main menu.

  2. Name the new project and change its location if necessary.

  3. Select the Create Git repository to place the new project under version control.

    You will be able to do it later at any time.

  4. Select a language that you want to use in your project. Click App general add if you want to add other languages available via plugins.

  5. Select Gradle in the list of Build system .

  6. Specify project's SDK (JDK) or use the default one.

  7. The selected Add sample code option will create a file with a basic code sample.

  8. Select Gradle DSL . You can select Groovy for traditional syntax or Kotlin as an alternative.

  9. In Advanced Settings , specify the fields which resemble the Maven coordinates . These settings might be helpful if you decide to deploy your project to a Maven repository. The fields you specify are added to the build.gradle file.

    • Gradle distribution : select Gradle wrapper that is a default-preferable option or Local installation when you want to use the specific local Gradle version.

    • Gradle version : if the wrapper option is selected, the latest Gradle distribution will be used unless you unselect the Auto-select option and select the specific version from the drop-down list.

      Alternatively, if the Local installation was selected then the version you defined locally is used.

    • Auto-select : unselect this option to specify the Gradle version you want to use in your project.

    • Use these settings for future projects : select this checkbox to use the configured Gradle version in your future projects.

    • GroupId - groupId of the new project. You can omit this field if you plan to deploy your project locally.

    • ArtifactId - artifactId that is added as a name of your new project.

    • Version - version of the new project. By default, this field is specified automatically.

  10. Click Create .

Create a Java EE project with Gradle as a build tool

  1. Launch the New Project wizard . If no project is currently opened in IntelliJ IDEA, click New Project on the welcome screen. Otherwise, select File | New | Project from the main menu.

  2. Under the Generators section, select Jakarta EE .

  3. Configure your project selecting the appropriate options such as your project's name, location, language, and select Gradle as your build tool.

  4. Click Create .

    IntelliJ IDEA creates a Gradle project with the dedicated Gradle tool window and adds necessary dependencies.

    For the more detailed information, refer to Tutorial: Your first Java EE application .

Open an existing Gradle project

  1. If no project is currently opened in IntelliJ IDEA, click Open on the welcome screen. Otherwise, select File | Open from the main menu.

    If you have some custom plugins that require you to import your project from the IntelliJ IDEA model, press Control+Shift+A and search for the Project from Existing Sources action.

  2. In the dialog that opens, select a directory containing a Gradle project and click OK .

    IntelliJ IDEA opens and syncs the project in the IDE.

If you need to adjust the Gradle settings options, refer to Gradle settings .

Check Gradle JVM and language level

  • Gradle JVM : when IntelliJ IDEA opens the Gradle project, it checks the gradle.properties file for the appropriate JVM version specified in org.gradle.java.home and uses it for the project. If it is not specified, then the project SDK is used. Alternatively, you can use the Gradle settings to configure the Gradle JVM.

  • Language level : the language level settings are applied for a source root or for a module. If a Gradle project has a single linked project then the project default language level is set to the minimum language level among the module language levels. The module language level is set to sourceCompatibility in the build.gradle file.

    The preview part is set to the conjunction of preview flags of the module source sets. The source set module language level is set to the corresponding combination of sourceCompatibility property and --enable-preview flag.

You can have multiple Gradle projects inside one IntelliJ IDEA project. It might be helpful if you keep parts of code in different projects, have some legacy projects on which you need to work, have Gradle composite build or work with microservices . You can link such projects in IntelliJ IDEA and manage them simultaneously.

When you open a Gradle project, the link of the project is established automatically and the Gradle tool window is enabled.

If an IntelliJ IDEA project is not linked to a Gradle project, then the Gradle tool window is disabled. In this case, IntelliJ IDEA displays a message with a link that quickly lets you reimport your Gradle project and enable the Gradle tool window. If the Gradle tool window is active, then you have at least one Gradle project linked.

  1. Open the Gradle tool window.

  2. In the Gradle tool window, click the Link Gradle Project icon to attach a Gradle project.

  3. In the dialog that opens, select the desired build.gradle file, and click OK .

  4. In the Import Module from Gradle window, specify options for the Gradle project that you are trying to link and click OK .

    The project is linked. The Gradle tool window shows the toolbar and a tree view of Gradle entities.

If you need to link back the previously unlinked project , in the Project tool window, right-click the added build.gradle or if it is a Gradle Kotlin module the build.gradle.kts file and select Import Gradle Project .

Add a new Gradle module to an existing Gradle project

You can add a Gradle module to a project in which you are already working.

  1. In a project, go to File| New | Module to open the New Module wizard.

  2. If the existing project is not the Gradle project then the process of adding a module is the same as Creating a new Gradle project . If the existing project is a Gradle project, then the process of adding a new module is shorter. You need to specify the name of your module in the ArtifactId field. The rest of the information is added automatically, and you can use either the default settings or change them according to your preferences. Also, note that Add as module to field, by default, displays the name of your project to which you are trying to add a module. You can click Add module to select a different name if you have other linked Gradle projects.

Convert a regular project into a Gradle project

  1. Open your project in IntelliJ IDEA.

  2. In the Project tool window, right-click the name of your project and select New | File .

  3. In the dialog that opens enter build.gradle and click OK .

  4. Open the build.gradle file in the editor, add the information you need and re-open your project. The following minimal information should be included in the project's build script file:

    plugins { id 'java' group 'org.example' version '1.0-SNAPSHOT' repositories { mavenCentral() sourceSets { main { java { srcDirs = ['src']