Contents:

Learn: The Java Developer Profession
Learn MoreMaven is a powerful tool for building Java projects that automates the processes of compilation, creating JAR files, forming distributions, and generating documentation. For small projects, you can avoid using Maven and manage the build via the command line. However, when working with large and complex projects, manual builds become difficult, as a command can consist of numerous steps. In such cases, developers often use batch or sh scripts to simplify the build process. Maven not only simplifies dependency management but also standardizes the build process, making it an indispensable tool for large teams and projects. Scripts often depend on platform-specific features, which can complicate the development process. To minimize this dependency and simplify the workflow, it is advisable to use project build tools such as Maven. Maven automates dependency management, building, and testing of applications, significantly increasing development efficiency and simplifying the integration of various components.
Migrating to Maven
Any standard project created in IDEA can be easily migrated to a project using the Maven dependency management system. The migration process optimizes library and dependency management and improves project builds. Maven provides a more structured approach to development, simplifying project collaboration and maintenance. When migrating to Maven, it is important to follow the recommendations for setting up the pom.xml file, which will allow you to effectively manage the project configuration and its dependencies.
This article covers the JetBrains IDEA Community IDE version 2021.1. Please note that if you are using a different version, the interface may differ significantly. The information is guaranteed to be relevant for the specified version, so users are advised to familiarize themselves with the interface features of their IDE version for more efficient work.
To achieve this goal, follow these recommendations:
- Select the project or module that you will add to Maven - in our example, this will be the LambdaExpressions module.

- Right-click on the project/module name and select Add Framework Support…

- Select the Maven project type and click OK.

- After this, if your project is under Git control, you will be prompted to add the pom.xml file to Git tracking. To do this, click Add - your pom.xml will immediately be added to the stage and will be ready for commit.
Attention!
To make changes in Git, the pom.xml file can be added to the commit later. To do this, just click the «Cancel» button. If you previously selected the default action and checked the "Remember, don't ask again" option, this window will not appear.

- You will be asked to set the values groupId, artifactId, version in pom.xml - do this using editor.

In Maven, each project is uniquely identified by a combination of groupId and artifactId. These identifiers play a key role in organizing and managing projects, allowing you to avoid conflicts between different artifacts. GroupId typically reflects the unique name of a group or organization, and artifactId identifies a specific artifact or project. Proper use of these identifiers facilitates effective dependency management and simplifies the software build process.
- groupId — the name of the organization or department. Typically, the same rules apply here as for naming packages in Java — write the domain name of the organization or project site. For example, ru.sendel.
- artifactId — the name of your project. For example, LambdaExpressions.
- version — the version of the project. If the code state for the project is not committed, -SNAPSHOT is appended to the end of the version name. This means that the version is in development and the resulting JAR file may change. For example: 1.4.6, 1.0-SNAPSHOT.
Importing pom.xml Changes
After making changes to the pom.xml file, you must update the project configuration for the changes to take effect. Depending on your IntelliJ IDEA version, you need to perform certain actions to activate the new configuration.
- For IntelliJ IDEA 2020.1 and higher, use the keyboard shortcut Ctrl + Shift + O or click the Reimport button in the pop-up window.

- For IntelliJ IDEA versions up to 2020.1 After editing the properties in the file, read (import) the changes into the project. To do this, right-click on the pom.xml file, and in the Project window, select Maven → Reimport.

Error Error: java: error: release version 5 not supported
After trying to run the project, an error message may appear. This warning indicates that a problem occurred during program initialization or execution. It's important to carefully examine the error message, as it may contain clues about what exactly went wrong. Checking configuration files, dependencies, and the software version can help diagnose the problem. You should also consider consulting the documentation or the developer community for additional information and a solution. Correctly interpreting the error message and taking appropriate action can significantly speed up the remediation process.

By default, Maven compiles the project using language version 1.5 (JDK 5). This can lead to errors if the project uses libraries compatible with newer versions of Java. To avoid such problems, it is recommended to explicitly specify the language version in the project configuration. This will ensure compatibility with the libraries you use and improve build stability.
To tell Maven which library to use, you need to explicitly specify it in the pom.xml file by adding the appropriate block. It's important to set dependencies correctly to ensure the project builds with the required libraries. You must specify the group, artifact, and version of the library you want to use. Correct pom.xml configuration ensures the stability and compatibility of your project with various libraries and frameworks.
This entry refers to JDK 8. If you need to build a project for JDK 14, the entry format will change as follows:
Java developer profession
You will learn programming from scratch in Java and create web applications using the Spring framework. In six months, gain fundamental skills and build a portfolio, and we'll help you find a job.
Find out more
