The IntelliJ IDEA compilation and building process compiles source files and brings together external libraries, properties files, and configurations to produce a living application. IntelliJ IDEA uses a compiler that works according to the Java specification. You can compile a single file, use the incremental build for a module or a project, and rebuild a project from scratch. If you have a pure Java or a Kotlin project we recommend that you use IntelliJ IDEA to build your project since IntelliJ IDEA supports the incremental build which significantly speeds up the building process. However, IntelliJ IDEA native builder might not correctly build the Gradle or Maven project if its build script file uses custom plugins or tasks. In this case, the build delegation to
Gradle or Maven can help you build your project correctly. Open the needed file in the editor and from
the main menu, select
(Ctrl+Shift+F9). Alternatively, in the Project tool window, right-click the class you need and from the context menu, select Recompile 'class name'. If errors occur during the compilation process,
IntelliJ IDEA will display them in the Review compilation and build output along with warning messages. When you compile your source code, IntelliJ IDEA automatically creates an output directory that
contains compiled .class files. Inside the output directory, IntelliJ IDEA also creates subdirectories for each of your modules. The default paths for subdirectories are as follows: Sources: <ProjectFolder>/out/production/<ModuleName> Tests: <ProjectFolder>/out/test/<ModuleName> At the project level, you can change the <ProjectFolder>/out part of the output path. If you do so (say, specify some <OutputFolder> instead of <ProjectFolder>/out) but don't redefine the paths at the module level, the compilation results will go to <OutputFolder>/production/<ModuleName> and <OutputFolder>/test/<ModuleName>. At the module level, you can specify any desirable compilation output location for the module sources and tests individually. Specify compilation output folders
BuildWhen you execute the Build command, IntelliJ IDEA compiles all the classes inside your build target and places them inside the output directory. When you change any class inside the build target and then execute the build action, IntelliJ IDEA performs the incremental build that compiles only the changed classes. IntelliJ IDEA also recursively builds the classes' dependencies. Build a module, or a project
If you add a module dependency to your primary module and build the module, IntelliJ IDEA builds the dependent module as well and displays it in the output directory alongside the primary one. If the dependent module has its own module dependencies, then IntelliJ IDEA compiles all of them recursively starting with the least dependent module. The way the module dependencies are ordered may be very important for the compilation to succeed. If any two JAR files contain classes with the same name, the IntelliJ IDEA compiler will use the classes from the first JAR file it locates in the classpath. For more information, see Module dependencies. RebuildWhen you execute a rebuild command, IntelliJ IDEA cleans out the entire output directory, deletes the build caches and builds a project, or a module from scratch. It might be helpful, when the classpath entries have changed. For example, SDKs or libraries that the project uses are added, removed or altered. Rebuild a module, or a project
Background compilation (auto-build)You can configure IntelliJ IDEA to build your project automatically, every time you make changes to it. The results of the background compilation are displayed in the Problems tool window. Configure the background compilation
Compile before runningBy default, when you run an application, IntelliJ IDEA compiles the module where the classes you are trying to run are located. If you want to change that behavior, you can do so in the Run/Debug Configurations dialog. Configure a run/debug configuration
Review compilation and build outputIntelliJ IDEA reports compilation and building results in the Build tool window, which displays messages about errors and warnings as well as successful steps of compilation. If you configured an auto-build, then IntelliJ IDEA uses the Problems tool window for messages. The window is available even if the build was executed successfully. To open it, click Auto-build on the status bar. Double-click a message to jump to the problem in the source code. If you need to adjust the compiler settings, click . Package an application into a JARWhen the code is compiled and ready, you can package your application in a Java archive (JAR) to share it with other developers. A built Java archive is called an artifact. Create an artifact configuration for the JAR
Build the JAR artifact
When you're building a project, resources stored in the Resources root are copied into the compilation output folder by default. If necessary, you can specify another directory within the output folder to place resources. Run a packaged JARTo run a Java application packaged in a JAR, IntelliJ IDEA allows you to create a dedicated run configuration. Create a run configuration
Run configurations allow you to define how you want to run your application, with which arguments and options. You can have multiple run configurations for the same application, each with its own settings. Execute the run configuration
If the process has exited successfully, then the application is packaged correctly. Last modified: 07 December 2022 What does build in IntelliJ do?Build command, IntelliJ IDEA compiles all the classes inside your build target and places them inside the output directory. When you change any class inside the build target and then execute the build action, IntelliJ IDEA performs the incremental build that compiles only the changed classes.
What is a build file?A BUILD file in a given directory describes targets that own the source files in or under that directory.
How do I create a build file in IntelliJ?In the Project tool window, select the directory, where the build file should be created. Right-click the directory and from the context menu, select New | File ( Alt+Insert ). In the New File dialog, specify the name of the new file with the xml extension, for example, build.
Where is build file properties in IntelliJ?Opening the Build File properties dialog. In the Ant tool window, select the desired build file.. Do one of the following: On the context menu of the selection, choose Properties. Click. button on the Ant Build toolbar. Press Alt+Enter .. |