445

I have a project on Bitbucket. Only the sources are committed. To retrieve the project onto a new machine, I used Version Control > Checkout from Version Control from within IntelliJ.

It then asks whether I would like to create a new project from this source, to which I reply Yes. So far, so good. It creates a nice little Java project for me, consisting of a single module.

However, my goal in pulling this project into IntelliJ was to turn it into a Maven project. I cannot find any option anywhere that will let me do this!

Is there a way to have IntelliJ just generate a basic empty pom.xml for me, with a name and an artifactId and a repository? Or, is there a way to import the project as a Maven project in the first place? (Whenever I try to create a project from existing source, it only gives me the option of a Java project.)

Neil Traft
  • 18,367
  • 15
  • 63
  • 70

12 Answers12

804

Right-click on the module, select "Add framework support...", and check the "Maven" technology.

enter image description here

enter image description here

(This also creates a pom.xml for you to modify.)

If you mean adding source repository elements, I think you need to do that manually–not sure.

Pre-IntelliJ 13 this won't convert the project to the Maven Standard Directory Layout, 13+ it will.

Gaurav Khurana
  • 3,423
  • 2
  • 29
  • 38
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • 3
    Exactly what I was looking for! And yeah, I meant adding the default maven2 "Central" repository element. But I can add that myself, no big deal. – Neil Traft Oct 04 '11 at 03:08
  • 1
    Cool. But you shouldn't have to add that; it's already the default. – Dave Newton Oct 04 '11 at 03:12
  • 55
    What happens if I don't have that option? –  Aug 05 '14 at 21:06
  • @LukeyBoylsXen Check your plugins. Should be there, though. – Dave Newton Aug 05 '14 at 23:05
  • 2
    which "plugins"? I have 2 maven plugs (came default with IntelliJ). Still no "Maven" option in Add Frameworks – Nick Feb 20 '17 at 21:55
  • @Nick It's quite likely the IDE has changed a bit in the last five years. – Dave Newton Feb 23 '17 at 15:16
  • Re: no "Maven" option: i believe it is due to working on an IntelliJ plugin for which there is no maven support. @Dave Newton - you make a good point, always need to consider that for older questions and answers. – Nick Feb 23 '17 at 15:35
  • 1
    sorry for reviving this old post but is there an automatic way to put the jsf dependencies into the pom ? The pom gets created but it's empty, i would like to have all the proper dependencies of a jsf project inside the pom. – MrSir Nov 25 '17 at 13:07
  • @MrSir There's probably an archetype for JSF projects, and using an archetype is one of the options IIRC. – Dave Newton Nov 25 '17 at 14:16
  • @DaveNewton that was my first idea, but i'm having issues with that, i made a [question](https://stackoverflow.com/questions/47478855/how-to-build-a-jsf-application-in-intellij-using-maven?noredirect=1#comment81926817_47478855) about it. – MrSir Nov 25 '17 at 14:20
  • @Nick - Maven can be added as a framework to be selected, or made visible in the "Add Framework Support" by changing the intellij Settings: File -> Settings-> Build, Execution, Deployment -> Build Tools -> Maven -> Importing: tick Import Maven projects automatically – Petronella Jan 07 '19 at 14:49
82

A visual for those that benefit from it.

enter image description here

After right-clicking the project name ("test" in this example), select "Add framework support" and check the "Maven" option.

kgui
  • 4,015
  • 5
  • 41
  • 53
37
  1. Open 'Maven projects' (tab on the right side).
  2. Use 'Add Maven Projects'
  3. Find your pom.xml
FazoM
  • 4,777
  • 6
  • 43
  • 61
  • 1
    When I had a parent director git URL when many sub projects, the sub projects were not recognized as Maven. This answer helped. To make it clear, this functionality is available on the Maven Tool Window. – Sylvester Mar 22 '19 at 15:13
  • This answer helped me to re-associate a Gradle project back to Maven. Just needed to unlink it (use the minus sign) on the analogous Gradle menu. – riddle_me_this May 22 '20 at 14:19
  • Great hint, I was moving projects under the parent and "Add framework support" was not available for me. Your solution works very nice. – Olga Oct 13 '22 at 21:50
8

Just follow the steps:

  1. Right click to on any module pox.xml and then chose "Add as Maven Project"

enter image description here

  1. Next to varify it, go to the maven tab, you will see the project with all maven goal which you can use:

enter image description here

Indrajeet Gour
  • 4,020
  • 5
  • 43
  • 70
7

I want to add the important hint that converting a project like this can have side effects which are noticeable when you have a larger project. This is due the fact that Intellij Idea (2017) takes some important settings only from the pom.xml then which can lead to some confusion, following sections are affected at least:

  1. Annotation settings are changed for the modules
  2. Compiler output path is changed for the modules
  3. Resources settings are ignored totally and only taken from pom.xml
  4. Module dependencies are messed up and have to checked
  5. Language/Encoding settings are changed for the modules

All these points need review and adjusting but after this it works like charm.

Further more unfortunately there is no sufficient pom.xml template created, I have added an example which might help to solve most problems.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Name</groupId>
<artifactId>Artifact</artifactId>
<version>4.0</version>
<properties>
    <!-- Generic properties -->
    <java.version>1.8</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
    <!--All dependencies to put here, including module dependencies-->
</dependencies>
<build>
    <directory>${project.basedir}/target</directory>
    <outputDirectory>${project.build.directory}/classes</outputDirectory>
    <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
    <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
    <testSourceDirectory> ${project.basedir}/src/test/java</testSourceDirectory>

    <resources>
        <resource>
            <directory>${project.basedir}/src/main/java</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
        <resource>
            <directory>${project.basedir}/src/main/resources</directory>
            <includes>
                <include>**/*</include>
            </includes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <annotationProcessors/>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Edit 2019:

  • Added recursive resource scan
  • Added directory specification which might be important to avoid confusion of IDEA recarding the content root structure
Thomas
  • 1,622
  • 17
  • 24
3

I had a different scenario, but still landed on this answer.
I had imported my root project folder containing multiple Maven projects but also some other stuff used in this project.
IntelliJ recognised the Java files, but didn't resolve the Maven dependencies.

I fixed this by performing a right-click on each pom and then "Add as maven project"

LostMage
  • 451
  • 4
  • 11
3

I have resolved this same issue by doing below steps:

  1. File > Close Project

  2. Import Project

  3. Select you project via the system file popup

  4. Check "Import project from external model" radio button and select Maven entry

  5. And some Next buttons (select JDK, ...)

Then the project will be imported as Maven module.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Walid Ammou
  • 390
  • 1
  • 6
  • 21
2

This fixed it for me: Open maven projects tab on the right. Add the pom if not yet present, then click refresh on the top left of the tab.

ZoltanT
  • 96
  • 1
  • 6
1

The easiest way is to add the project as a Maven project directly. To do this, in the project explorer on the left, right-click on the POM file for the project, towards the bottom of the context menu, you will see an option called 'Add as Maven Project', click it. This will automatically convert the project to a Maven project

Testilla
  • 602
  • 8
  • 21
1
  1. Right-click on the module
  2. Select "Add framework support"
  3. Click the "Maven" option.

Note: This will convert the current project into maven driven project create the pom.xml file automatically. The dependencies can be added then.

Enable Auto Import of Dependencies

(InteliJ IDEA 14.1.1 on Ubuntu)

Settings > Build, Execution, Deployment > Build Tools > Maven > Importing > [X] Import Maven projects automatically

Run as maven project

Creating a new Run/Debug Configuration of type maven and adding the command clean install

Finally clicking the green button to run that Run/Debug Configuration, this will run build the project using apache maven.

Du-Lacoste
  • 11,530
  • 2
  • 71
  • 51
1

Using IntelliJ Idea 2022.3.3, here is the easiest way you can do it:

  • Right click on root of your project in Explorer on the left side.
  • Select "Add framework support" (3rd option from the last as shown in image)
  • Choose Maven enter image description here
Shreyansh Jain
  • 96
  • 1
  • 2
  • 8
0

Update on version Intellij IDEA 2020.2.3

Settings -> Build,Execution,Deployment -> Build Tools -> Maven -> Importing and click "create module groups for multi-module Maven projects".

Then Apply and you can see that option in "Add Framework Support..."

enter image description here

Alex Yao
  • 99
  • 1
  • 7