Intellij switch from sbt to maven - intellij-idea

I have an SBT project opened in Intellij.
I want to convert it to Maven.
I created a pom.xml file, I removed build.sbt and now I want Intellij to see it as a Maven project.
If I do:
File -> New -> Project From Existing Sources
Then Intellij won't offer me the option to open it as a Maven project.
If I select Add Maven Project then I am unable to choose the current directory.
So how can I make Intellij see the project as a Maven project?

Use File | Open..., select the pom.xml file, choose "Open as Project" in the message box that appears.

Related

How to force IntelliJ IDEA to use the name of the jar-file specified in the gradle.build as artifact name?

I have multi-project web application that configurable by Gradle. In one subproject (let's call it 'XYZ') I specify desired jar-file name.
jar {
archiveName 'archiveName.jar'
}
When I import this project into IntelliJ IDEA (File -> New -> Project from Existing Sources...), IntelliJ IDEA generate artifact description for WAR file. In this artifact description subproject JAR file in WEB-IBF/lib named as <rootProject.name>-XYZ.jar.
How to force IntelliJ IDEA to use the name of the jar-file specified in the gradle.build as artifact name?
Delegate the build to Gradle or use Gradle tasks to build the artifacts instead of IntelliJ IDEA. Vote for the related request.

What option to select when cloning Git project in IntelliJ?

I have cloned Gradle project from GitHub in IntelliJ and then got the following dialog:
Should I select "existing sources" because my sources exist and not external, or should I select "external model" because it has Gradle specification?
You should choose Gradle becouse only this way the IDE will properly find and use build.gradle files.
You should choose external model. You want IntelliJ to look at your Gradle file and decide how to set itself up based on what is in your Gradle file.
You use the existing sources option when you don't have Gradle file or Maven pom and you need IntelliJ to look at the sources and figure out what to do without a file to guide it.
There is some documentation here: https://www.jetbrains.com/help/idea/2016.3/creating-a-project-by-importing-existing-sources.html

How to use gradle in intellij idea plugin project?

I am developing an idea plugin, and it is an intellij idea project.
I want to use gradle to manage the dependency.
How to config?
There is now a Gradle plugin for building IntelliJ Platform Plugins. In order to use it, you will need to add the following snippet to your build.gradle file.
plugins {
id "org.jetbrains.intellij" version "0.0.31"
}
apply plugin: 'org.jetbrains.intellij'
For more information, please see this guide to help you get started.
Ok, there are multiple ways to create an IntelliJ project, "templates" if you like, and unfortunately you can only pick one of them (IntelliJ plugin or gradle).
Thankfully, it's easy to configure a project for gradle in IntelliJ.
First, create a new project from the IntelliJ Platform Plugin template. You don't need to choose any Additional Libraries and Frameworks. This will give you a project structure including META-INF/plugin.xml and the Project SDK should be something like IDEA IU-129.451.
From here, simply create a new file named build.gradle at the top level of your project, including for example this line:
apply plugin: 'java'
Now, close the project. You can now use File -> Import Project..., choose the build.gradle file that you just created, and import the project. Accept the defaults for importing and hit OK.
The project is now opened with both gradle and intellij plugin enabled!
Notice that the source root src has disappeared and you will need to right click on src in the Project pane and select Mark Directory As -> Source Root.
To prepare the plugin for deployment, there is still the menu option in the Build menu for that - if you want to automate that part via gradle, good luck and please let us know how it's done ;)

Building war with Gradle, Debugging with IntelliJ IDEA

I have JavaEE webapp project(named ProjectA) developed in IntelliJ IDEA.It has build.gradle file that applies war plugin :
apply plugin: 'war'
I want to debug(or run) gradle generated war file instead of debugging auto generated intellij artifact.
It's very important for me that I can update classes changed during debugging without need to restart server.
How can I do it?
Note that :
1) When click refresh button in gradle plugin tab () Intellij updates all project configurations(for example module dependencies) and generate artifacts.I called it auto generated intellij artifact.
For run it,I should only create new local Tomcat Server configuration and add artifact to deployment tab.
2) In addition,there is some gradle tasks(clean,build,war and etc).I can execute build task or war task to generate war file.I called it gradle generated war file.
Instead of deploying the IntelliJ build artifact, you can deploy an "External source" by clicking the "+" button in your final screenshot. You can then navigate to the artifact built by Gradle (in this case, the .war file in build/libs).
Second, you can instruct IntelliJ to run a Gradle task before running the configuration. Again, in your final screenshot, I would remove the second step labeled "Build 'Gradle ...' artifact" and add a step to run the Gradle war task.

How to add new maven module into existing maven project

I mean is there a possibility to run some maven command to add new module to existing project , or manually create folder and needed changes to pom.xmls ?
If you are using archetypes, mvn archetype:generate will create subproject's POM and structure, and will also set it as a module of the current project.
If you are working with Eclipse (m2eclipse) you can add a maven-module via Eclipse (NetBeans and IntelliJ should work the same way) otherwise you have to do that manually...editing the pom and create the folder and put stuff into the new module.
To add to #khmarbaise's answer,
If you are using Idea, right click on your project's name on (Project view perspective) and New > Module. Select maven and follow the wizard.
If you want to create a new module in eclipse then do follow below steps:
Right click on root project. and select maven -> New maven module project
[1]: https://i.stack.imgur.com/DdPcP.png
but parent project must be pom project like add pom in your pom.xml of root project if you face any error.