How to quickly import `package.json` as npm-module? - npm

In IntelliJ I am used to create IntelliJ-Modules out of Maven pom.xml files. I just rightclick on the pom and choose + Add as Maven Project.
Is there something similar for npm modules? Maybe by rightclicking on the package.json file?
I do not want to use the cumbersome way of navigating to Project structure, Modules and clicking on +, import Module, and so on.

Related

How to import a project with modules and java packages in IntelliJ?

We have a java project with several modules. We use git for versioning and want the developers to be able to chose their own IDE. So we don't push .idea and .iml files with git. This means that developers in IntelliJ needs who clones from git needs to set up the project in IntelliJ as well. However we are having some issues with setting it up. In my own project it works fine and looks like:
Proejct Module (Is this a real module?)
⤷ Module A
⤷ src
⤷ main
⤷ java
⤷ Package 1
⤷ Package 2
⤷ test
⤷ Module B
Before we added packages to the project new developers could just pull from git and open Module P in IntelliJ, then go to project structure and import module from Module A and Module B. However if they try the same thing now IntelliJ tries to make the Modules main and test from Module A.
A workaround we temporarily use for this is to open Module A and B directly as separate IntelliJ projects. If we do this IntelliJ does not try to make modules out of main and test. However this is very inconveniant for us.
How can we fix this?
It's a good approach to make your source control system "agnostic" about the IDE and not check in .idea, *.iml and equivalent things from other IDE's.
However you really need to use a build control system like maven or gradle.
In my workplace we use maven for all our java projects. It's very simple to define a pom.xml at the root level which defines your modules, and many other things.
When you import a maven project into intellij, all the relevant IntelliJ modules are automatically created for you. In essence, you only need to import the pom.xml and you're good to go.
Otherwise it will be a nightmare to import and create modules every time you check out source from git. Maven isn't perfect but I highly recommend using either maven or gradle.
To define multi-modules from the root pom.xml, make a section like this:
<modules>
<module>module-A</module>
<module>module-B</module>
</modules>
And then the pom.xml in both module A and B should define a section referring to the root pom via the <parent> tag.

Groovy Project Setting in IDEA IntelliJ

I'm using IDEA to write groovy scripts for my jenkins job. So I have these imports
import groovy.json.JsonSlurper
import hudson.FilePath
import hudson.model.Node
import hudson.model.Slave
import jenkins.model.Jenkins
Before I added jenkins-core-2.9.jar into the project dependency, those jenkins classes are marked in red. Then I added the jar as a dependency by "File"->"Project Structure"->"Modules"->"Dependencies"
Then those red marks are gone. However, when I tried to run the script, it says Error:(14, 1) Groovyc: unable to resolve class jenkins.model.Jenkins. What else do I need to do?
I had the same problem and it was a permission issue. For me this command fixed it: sudo chmod o=r jenkins-core-2.73.3.jar
As stated in this link,
Note that if you configure a dependency through the Project Structure dialog, the dependency will only appear in the IntelliJ IDEA Project tool window, not in the Gradle tool window.
Adding the dependency like this only adds the dependency in the idea workspace. When you run the task either from the gradle tool window, or from an external command line tool, that dependency no longer exists. You should add it to your gradle dependencies:
dependencies {
compile "org.jenkins-ci.main:jenkins-core:2.9"
}
You can configure a repository to load this dependency from. This repository can be a file path, or a maven repository etc.
See here for more details on gradle dependency management.

Intellij IDEA can't import two gradle projects containing submodules with the same name

I have two gradle project:
projectA
submodule
projectB
submodule
Both submodules have the same name (but other group id). When I try to import both project to same workspace in IDEA, it imports one project correctly (root module + submodule) and only root module of second project. When I try to manually import missing submodule, it don't allow to it. because: "module "submodule" already exists in the project".
Is this a bug in IDEA ?
Is there any way to import this correctly?
I workaround this by change IDEA project name of "submodule" to "A-submodule", but I suppose that it must be a better way to do it.

How to refresh lib folder when update pom.xml?

I create a simple sample Spring MVC project, where IntelliJ 14 by default generate a pom with
<properties>
<spring.version>4.1.4.RELEASE</spring.version>
</properties>
I change it to
<properties>
<spring.version>3.2.0.RELEASE</spring.version>
</properties>
and choose Maven -> Reimport, I can see the dependencies are downloaded to my local .m2 folder
However, when I expend lib folder, all dependencies stays with previous version:
How can I get the latest dependencies showing in \lib folder? I tried to synchronize current project, but it doesn't help this matter
UPDATE
here is my maven setting
UPDATE 2
I forget some detail, which is I create a Spring MVC project in the beginning(so I think it may not be a maven project at the moment), then I right click pom.xml and set current project to maven project.
So I think the jar files listed in \lib folder may be downloaeded via intellij for Spring MVC application, however when I set current project to maven project, it does not remove or update the jar file under the \lib folder.
You should do:
1. Choose menu File \ Project Settings..., In section Build, Execution, Deployment \ Build Tools \ Maven \ Importing, check Import Maven projects automatically. It means IntelliJ IDEA will Synchronize Maven project model and IDEA project model each time when pom.xml is changed.
2. Try closing project, restart IntelliJ IDEA, then reopen the project.
3. Check your internet connection.
IntelliJ isn't shouldn't be looking there for your Maven project dependencies. It is should be using the libraries and resources in your .m2 directory instead.
Mind you, I've left those comments struck out on purpose; depending on your configuration, you may accidentally be doing that.
This is a picture of what the Dozer project looks like. It's a Maven project which I cloned a ways back to see how it worked.
You're going to have to check your Project Structure (Ctrl + Alt + Shift + S) to ensure that the libraries that are coming through are prefixed with "Maven:".
If they are, then the files in your lib folder aren't being used by your project.
In all actuality, those are your global libraries (which you can also find under Project Structure > Global Libraries). Any project has access to them.
If that's causing a conflict, consider deleting those JARs from your global libraries. If you need them for another project, consider adding it to the project's local libraries instead.

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 ;)