Please Re Import a Gradle Project and Try Again

Gradle projects

IntelliJ IDEA lets y'all manage Gradle projects. You lot tin link, ignore projects, piece of work with profiles, and synchronize changes in Gradle and IntelliJ IDEA projects. You can as well configure a Gradle composite build, Gradle source sets, the build and run actions.

  1. In the Gradle tool window, right-click a linked project.

  2. From the context menu, select Open Gradle config F4.

    IntelliJ Idea navigates to the appropriate Gradle configuration file and the related build.gradle file opens in the editor.

IntelliJ IDEA supports a navigation to subprojects inside the parent build script of a multi-module Gradle project.

  1. Open build.gradle of the parent project.

  2. Utilise the Ctrl+Click shortcut to navigate to a subproject.

    Navigate inside the build script

    You tin can also run across the usages of a subprojects with the Alt+F7 and cheque the results in the Detect tool window.

    the Find tool window

Unlink a linked Gradle projection

When you unlink a Gradle project, IntelliJ IDEA removes all relevant modules and content roots, removes the Gradle project from the Gradle tool window and stops its synchronization. It might be helpful if you need to fully remove the previously linked Gradle project from the current IntelliJ IDEA project.

  1. In the Gradle tool window, right-click a linked project.

  2. From the context menu, select Unlink Gradle project (Delete). Alternatively, y'all can select the linked project and click the Remove icon on the tool window'southward toolbar.

  3. In the Import Gradle Projects popup, clear the checkbox against the modules if yous don't want to delete the project from the IntelliJ Idea Project tool window.

  4. Click OK.

    If you need to link back the project, in the Project tool window, right-click the project's build.gradle file or build.gradle.kts if information technology is a Kotlin project, and select Import Gradle Project.

Ignore a Gradle project

You lot can de-activate a Gradle project using the Ignore Gradle Project option. In this case, IntelliJ Idea keeps the ignored Gradle projects and subprojects in the Gradle tool window, but stops their import (modules, content roots, tasks, and so on) to the project. However, IntelliJ Idea synchronizes the ignored projects with the current one. Information technology might be helpful if you demand to skip an irrelevant subproject such as buildSrc.

  1. In the Gradle tool window, right-click the project that yous want to ignore.

  2. From the context menu, select Ignore Gradle Project.

  3. In the window that opens, select projects and modules that you want to de-activate and click OK.

If you want to activate your Gradle projects or modules, select Unignore Gradle Projects from the context menu.

Orphan modules

Orphan modules are the IDE modules that were removed during the import process in the following cases:

  • when you lot manually deleted the modules in the build.gradle file and so re-imported your project.

  • when you used the Ignore Projection action, on a module in the Gradle tool window and and so re-imported your projection.

In all these cases, IntelliJ IDEA prompts you lot to restore removed modules.

Orphan modules notification

You can select the ones you want to restore in the Orphan Modules dialog.

Orphan modules dialog

Usually you exercise not demand to restore any modules since these are only the .iml files that contain the IDE modules settings. You only might want to restore them if you accept some user-defined settings specified inside them.

Reload a linked Gradle project

When you open a Gradle project the synchronization is done automatically. Also, when IntelliJ Idea detects any external changes to the build scripts, such as VCS updates or some edits made outside of the IDE, the related projects will be reloaded automatically.

If you need, you can manually trigger the synchronization of your project.

  1. In the Gradle tool window, right-click a linked project.

  2. From the context menu, select Reload Gradle projection the Reload icon.

    On invoking this activeness, IntelliJ Idea parses the project structure in the Gradle tool window.

    IntelliJ IDEA cannot reload just a part of your projection, information technology reloads the whole project including modules and dependencies.

    If you configure a dependency through the Projection Structure dialog (click the Project Structure button, from the master bill of fare), the dependency will only appear in the IntelliJ IDEA Project tool window, non in the Gradle tool window. Note that the next fourth dimension yous re-import your project, IntelliJ IDEA will remove the added dependency since IntelliJ IDEA considers the Gradle configuration as a single source of truth.

  3. Click the Build icon on the condition bar to view the results of the sync in the Build tool window.

Configure the auto-reload

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), go to .

    Alternatively, In the Gradle tool window, click Build Tools Settings and select the Auto-Reload Settings choice.

    the Gradle tool window
  2. In the Build tools settings, specify the following options:

    the Build Tools settings
    • Reload changes in the build scripts: this option is selected by default. If you lot want to disable the auto-reload and manually control the reloading procedure, unselect this checkbox.

    • Any changes: select this pick if you want to automatically reload the project afterward whatever changes you brand to build.gradle or external changes.

      Every fourth dimension you manually alter the Gradle build script in the editor, you need to load the changes. IntelliJ IDEA displays a notification icon in the right role of the editor suggesting to Load Gradle Changes made to the project (Ctrl+Shift+O).

      Editor: build.gradle

      With the Any changes option, IntelliJ Idea reloads all the changes automatically.

    • External chages: when you select this choice, IntelliJ Thought automatically reloads the project only later on the VCS changes and changes made to the build files outside the IDE.

Configure Gradle Blended Build

Earlier you start configuring your composite build, brand sure you have the Gradle version 3.one or later configured for your project.

You can use the settings.gradle file to include Gradle builds for your Gradle blended build.

  1. Open the settings.gradle file in the editor.

  2. Using the includeBuild control, specify the location of the builds you want to add as dependencies to your project.

You can also use the Gradle tool window to configure the blended build.

  1. Open a Gradle project.

  2. Link other Gradle projects that you want to use for the composite build.

  3. In the Gradle tool window, right-click your main project and from the context menu select Blended Build Configuration.

  4. In the Gradle Projection Build Composite dialog, select projects that you want to include in your Gradle composite build.

  5. Re-import your main Gradle project.

    IntelliJ IDEA finds the included Gradle projects and treats them as IntelliJ IDEA modules.

Use Gradle source sets

IntelliJ IDEA lets y'all use Gradle source sets in resolving Gradle projects. The source set up is treated as a module in an IntelliJ Thought projection. You can declare a custom source prepare and IntelliJ IDEA adds information technology equally a module to the projection.

When you create a Gradle project, IntelliJ Thought automatically creates a main Source Sets directory that contains 2 source sets - chief and test. IntelliJ IDEA also displays compile and runtime configurations in the Dependencies node in the Gradle tool window.

Gradle tool window: dependencies

Add a custom source set

  1. Open up the gradle.build file in the editor.

  2. Declare a custom source set (In our example, it's api).

    sourceSets { api } dependencies { compile sourceSets.api.output }

    (This source set contains interfaces without implementations. The implementations for the interfaces are in the default main source ready.)

  3. Open the Gradle tool window to run across that IntelliJ Idea added the api compile and runtime configurations.

    Gradle tool window: api Source Set

    The examination source set contains the advisable dependencies. Note that the default primary source ready has the compile dependency on the output of the api source set.

  4. From the chief menu, select File | Projection Structure Ctrl+Alt+Shift+S to open the project structure. Find that all source sets are represented equally separate modules that are grouped into a single module. If you click the test module and select the Dependencies tab, you will see a list of dependencies for the source set.

    Project Structure dialog / Dependencies tab

Use source sets for custom tests

Y'all can add together custom tests and run them separately from the primary ones using a source set up feature.

  1. Declare a source fix the same manner equally you would declare the custom source gear up. Besides the name of yous source set, specify an output directory and a task that will run the declared test. For example, declare an integration exam integrationTest.

    sourceSets { integrationTest { coffee { srcDir 'src/integrationtest/java' } resources { srcDir 'src/integrationtest/resource' } compileClasspath += sourceSets.main.runtimeClasspath } } job integrationTest(type: Test) { description = "Runs Integration Tests" testClassesDirs = sourceSets.integrationTest.output.classesDirs classpath += sourceSets.integrationTest.runtimeClasspath }

  2. In the Gradle tool window, click .

  3. In the listing that opens, double-click the integrationTest to run it.

    Gradle tool window: tasks

Add package prefixes in the Gradle project

If you use package prefixes in your Gradle projection, specify them in the build.gradle file. That way, everything is saved when you reimport your project.

For more than data, encounter https://github.com/JetBrains/gradle-idea-ext-plugin.

  1. Open the build.gradle file.

  2. Add the following plugin to support package prefixes:

    plugins { id "org.jetbrains.gradle.plugin.thought-ext" version "0.five" }

  3. Add the bundle prefixes. For instance, you have the following set of source sets:

    sourceSets { principal.coffee.srcDirs = [] main.java.srcDirs += "src" principal.coffee.srcDirs += "src/main/java" master.java.srcDirs += "../other-root/src/primary/java" }

    Add the package prefixes (in our case it is "org.example") to them with the following code:

    idea { module { settings { packagePrefix["src"] = "org.example" packagePrefix["src/main/java"] = "org.instance" packagePrefix["../other-root/src/main/java"] = "org.example" } } }

  4. Reimport your changes or apply the auto-import.

Specify IDE-specific settings in the build.gradle file

Using the gradle-idea-ext plugin, you can draw project settings such as project encodings, and the encoding for backdrop files inside the build.gradle file.

  1. Open the build.gradle file.

  2. Add the following plugin to support the encodings configuration:

    plugins { id "org.jetbrains.gradle.plugin.idea-ext" version "0.5" }

  3. Describe the project encodings with the post-obit code:

    import org.jetbrains.gradle.ext.EncodingConfiguration.BomPolicy idea { project { settings { encodings { encoding = 'windows-1251' bomPolicy = BomPolicy.WITH_NO_BOM properties { encoding = '<Organization Default>' transparentNativeToAsciiConversion = false } mapping['../sample-gradle-free/module'] = 'windows-1251' mapping['module'] = 'windows-1251' mapping['module2/src/main/java'] = 'windows-1251' } } } }

  4. Reimport your changes or use the car-import.

Use buildSrc

If y'all accept a big Gradle script that includes several Java, Peachy, or Kotlin classes, you can movement such classes to the buildSrc directory and refer to them from your main Gradle script. In this case you lot ensure the readability of the build.gradle file.

  1. If you don't take and existing buildSrc, add together information technology every bit a Gradle module to your chief project.

    Project tool window: buildSrc module
  2. Open your main build.gradle file in the editor and move the classes you need to the master subdirectory of the buildSrc directory.

    Project tool window: buildSrc
  3. Run your task from your project'south build.gradle file.

    Gradle main build file

Configure the build and run deportment

Past default, IntelliJ IDEA uses Gradle for edifice and running projects.

When you build a project (), IntelliJ IDEA invokes the corresponding tasks using Gradle. Gradle also executes the Run and Debug deportment from the menu. HotSwap is also gets triggered and the classes are reloaded during a debugging process.

If you have linked projects, you tin configure how to build each linked projection.

  1. In the Settings/Preferences dialog (Ctrl+Alt+South), go to .

  2. On the Gradle settings page, in the Gradle Projects section, select a Gradle project you need.

  3. In the Build and run using listing, select the advisable selection and click OK to save the changes.

If you want to use IntelliJ IDEA for edifice a Gradle project, y'all need to explicitly specify so.

Delegate a build to IntelliJ Thought

It might be helpful to apply IntelliJ Thought for building a pure Java or Kotlin projection. Information technology could speed up the building process since IntelliJ IDEA supports the incremental build. Yet, go along in mind that the IntelliJ IDEA compiler does not back up some parts of the Gradle project build processing and might cause issues in edifice your project correctly.

  1. Click Gradle settings in the Gradle tool window.

    Alternatively, in the Settings/Preferences dialog (Ctrl+Alt+S), become to .

  2. On the Gradle page, from the Build and run using list, select Intellij IDEA.

    the Gradle settings

    Note that the Run test using choice stays active, and you tin select how you want to run your tests even if you lot delegated all build and run actions to IntelliJ Idea.

  3. Click OK.

Now if you build your Gradle project, it will be built with IntelliJ Idea.

Terminal modified: 17 March 2022

orrwhict1950.blogspot.com

Source: https://www.jetbrains.com/help/idea/work-with-gradle-projects.html

0 Response to "Please Re Import a Gradle Project and Try Again"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel