Intellij not importing dependencies of modules - java

IntelliJ is not importing my modules dependencies for some reason. Like it's not taking into account my modules pom.xml. The dependencies added for example in the core module don't figure in the External library of the subject. As I'm not yet that familiar with intelliJ I assume the problem comes from the project structure so here it is:

You need to import the project as a "Maven Project".
Remove the "wallbang" module with the "-" button.
Click "+" -> "Import Module", then select the pom.xml.
Configure it using the wizard.
Click "Ok"
That should open up the Maven view and automatically include all dependencies.

Related

How to add a project to build path in IntelliJ Idea

I've recently converted over to IntelliJ Idea 13, previously in eclipse I was able to add a project to another project's build path. I'm not able to accomplish this in IntelliJ.
How can I add project1 to project2's build path so that I can use it as a dependency. I don't want to make that project a JAR because I'm still developing it.
Following this similar previous question:
Intellij - Add project dependency like in Eclipse
I was not able to successfully achieve my goal.
In File > Project Structure > Modules
I see the project I'd like to add to my build path (DataProvider) but it's highlighted red, and the bottom warning text states "Invalid item 'DataProvider' in dependencies list'
Any help or assistance would be much appreciated.
Edit:
Solution (Thanks #leeor)
Import project as a module
File > Import Module > (Select Project to be imported)
This will add that project to the project view pane on the left side of the screen.
Then go to your current project
File > Project Structure > Module > (Select your current project)
Under Dependencies
Check mark your project (now a module) you want to import and then click apply and then OK.
Done!
Using IntelliJ Idea 13.1.6 on Mac
If you want to depend on another module without it being jar, you need to import that as a module into the same project. It doesn't look like DataProvider is imported since it doesn't appear in the module list.

Intellij - Add project dependency like in Eclipse

I'm switching to Intellij and trying to do the same thing as in Eclipse. In Eclipse, you can add a project as a dependency in another project (project properties -> "Java Build Path" -> "Projects" -> Click on my library project).
The current situation is that I'm developing a library and I can test the features in another project without building the jar file every time I add new stuff to the library.
I'm trying to achieve this with Intellij but without success (the projects are both imported in Intellij).
How can I do that?
File > Project Structure. Then choose your module, and add any dependency, either Jar, Library or Module:
Larger image here: http://i.imgur.com/rjdxJHx.png
From File -> project structure, select Modules. You will be presented with all the added projects. Click a project and from the right hand side select Dependencies tab. This will show you projects that are not imported in red coloured text. HTH
File > Project Structure > Project Settings > Modules
Add the module you want to add as dependency.
Add your module dependency in your project.
If you use Maven you'll see the following message:
Module 'your-module' is imported from Maven. Any changes made in its
configuration may be lost after reimporting.
→ Add your project to your pom.xml
If you don't do that, your dependency will be removed each time you reimport/refresh maven projects.

Can Intellij IDEA automatically replace Maven dependencies with module dependencies?

I'm working with a Java project in Intellij IDEA where we have a lot of internal, standalone, Maven dependencies.
I have the source code for these dependencies imported into my IDEA project as modules, but when I select Go To -> Implementation(s) on a class that is part of an internal Maven dependency (and that I have also imported as a module in my project) I'm navigated to a decompiled view of the class in the Maven dependency (jar) and not the source code file of that class that I imported as a module.
To solve this I need to do the following:
Open Module Settings on the module using the internal Maven dependency
Find and remove the internal Maven module in the Dependencies list
Add a new Module Dependency and then select the imported module that corresponds to the internal Maven dependency
Is there any way to have IDEA figuring out this automatically or do I have to do this manual procedure over and over?
To add another maven project (that is not part of your main project) as a dependency:
open you main project
in Maven Projects Tool Window click on green + button and select pom.xml of a dependency
repeat 2 as required
Source:
https://www.jetbrains.com/idea/help/maven-projects-tool-window.html?search=maven%20project
Lets say you have a maven module A which has module B as a dependency.
If you import both modules into one IntelliJ project, IntelliJ will automatically use the imported module B instead of the maven artifact from repository - but you must import it as a maven module.
If you then run some test or application via IntelliJ from module A, it will use it's own compiled classes from module B and not the maven artifact from repository, navigation in the code and everything else will work as expected.
If this does not work, then you should report a bug.
I'd suggest that you are using intellij incorrectly in this example. If you are referring to your maven dependencies as intellij modules, it will get confused.
You should either:
Change these maven dependencies to be maven modules.
Remove these intellij modules as intellij modules and set up your maven build so you can download the source from your maven dependencies.

Adding POM Dependency in Eclipse build path

I have a project with a number of POM files. I have done a clean install and eclipse:eclipse. I would like to import the project as a normal project rather than Maven project. When I imported the project as normal project , I was not able to see the Maven dependencies present in POM in eclipse's build path. Is importing the project as Maven project only way of doing it? When I import the project as Maven project I see a number projects in eclipse workspace (one for each POM). However I would like to view this as a single project in eclipse workspace.
UPDATE: The classpath files of the child projects contain the dependent jar files , however it is not added to build path when the main project is added. Only the entries in classpath file of the main project is being added.
Given that you refer to "Maven project", are you using an eclipse plugin for Maven like M2Eclipse?
Assuming you are using M2Eclipse, the Maven Dependencies Library is automatically enabled for a Maven project. For a normal Java project, importing the library would force you to configure the project as a Maven project (On the context menu for the project, select Configure -> Convert to Maven Project).
Having said that, while you import your Maven project, you will notice an "Advanced" option (towards the lower section of the "Import Maven Projects" dialog). When you expand this option, there will be a checkbox to "Resolve Workspace Projects" - this is checked by default and is hence responsible for importing the child modules as separate projects. If you uncheck this, it will import only the parent module as the project and all children modules will be in sb folders under the parent module.
IMO, resolving the projects provides greater clarity, but then again this is very much a personal choice.
Hope that helps.
Eclipse doesn't support nested projects, and Maven kinda forces you to. So you can't really push everything into one project.
Doing a cursory google search led me to this, which might be helpful: http://warpedjavaguy.wordpress.com/2011/08/08/how-i-defeated-the-maven-release-plugin-in-a-flat-structured-multi-module-project/
You might also check out the following two online books from Sonatype:
Maven: The Complete Reference and Developing with Eclipse and Maven
Personally, I create Working Sets for each multi-module project and add all the individual projects to it. This enables me to see them all grouped together, this might be to your liking.
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Fconcepts%2Fcworkset.htm
Once you have created the working set you can enable/disable them in the menu in Project Explorer and configure the project explorer to display the working set as the root element in the tree rather than the project.

In eclipse, maven dependencies are overriding project dependencies

I have a "master project" that uses several "modules". The modules are in the pom.xml, but I also have the code for the modules as projects in Eclipse. I defined the modules as project dependencies both in "Properties|Project References" and in "Properties|Java Build Path". I also made sure all of the Eclipse projects are at the top of "Order and Export" in Java Build Path.
The master project is not recognizing changes to the modules within eclipse. When I press F3 to see the code, it opens java source from my .m2 directory. It's obviously ignoring my Eclipse projects. Am I missing some setting? What should I do?
You don't need to add the dependent projects into the Project references (at least when using m2eclipse-plugin), just add them as dependencies on your masters' pom.xml. I haven't had the need to touch the Build path since I've started using Maven in Eclipse.
Make sure you have enabled the Workspace resolution of the plugin by right clicking on project root -> Maven -> Enable Workspace Resolution. If it says "Disable Workspace Resolution", it is already enabled. You may also need to run "Update project configuration" under the same menu.
This way when you run your master-project from within Eclipse, any changes made to the other projects will be "visible" to the master (and you can actually use hot swap during runtime even on the other projects).
If you're using Maven, you pretty much want to commit to Maven. Even if you do configure Eclipse with Eclipse-specific dependencies, anytime you update your project configuration using Maven, it will do a complete rewrite of your configuration.
I strongly recommend converting any of your other project build dependencies into Maven-enabled projects that can be used as Maven dependencies.
In your specific case (through using the Maven modules), this means ensuring that each of your modules are imported into Eclipse as m2e-enabled projects. m2e will then automatically wire in the dependencies between modules and other dependent projects.
Im scratching my head as to why you would need your modules defined as dependencies on your top level project. Are you trying to avoid having to define the (cross) dependencies at a module level? In any case, as per other suggestions, first of all put your dependencies in the correct places in your POM, then either run
mvn eclipse:clean eclipse:eclipse
to update your Eclipse settings, or better still, make sure m2eclipse is installed and import your maven projects directly into the IDE.

Categories