IntelliJ - use imported modules as dependencies like maven projects in Eclipse - eclipse

I've been asking myself this question for a couple of years but never really found the solution.
I used to work with eclipse (on maven java projects). I could import a project -let's call it 'proj-A'- and if one of proj-A's dependencies was found in the workspace with the same exact version, eclipse would use that project's source instead of the jar from the repository. This way I could edit a library and see the changes in the project that used it right away.
For example, in Eclipse, if proj-A depended on dep-B-1.2.3-SNAPSHOT, I could import proj-A and dep-B in the same workspace, and if dep-B version was 1.2.3-SNAPSHOT I could see the live changes in dep-B sources from proj-A classes.
I'm now working in scala in IntelliJ. I don't seem to be able to do that. what's the best workflow if you want to avoid publishing the library and then reloading the whole project that uses it along with all its dependencies every time?
If I import proj-A as sbt project I can find dep-B snapshot jar in the libraries (loaded from some repo, be it local or remote), and I can't see the code changes to the dep-B module imported in the same intellij project (i.e. the equivalent of eclispe workspace).
If I manually remove the dep-B jar and add the dep-B module as a dependency for proj-A I'm forced to do it everytime I reimport proj-A for some reason.
I'm not sure there's a way of doing this as straightforward as the eclipse way (automatic), but maybe you know something I don't ...
thanks

It should work out of box for dependencies, which are imported to the project as modules, no additional settings needed. At least for Java.
Just do not run a Maven goal, that would use dependencies from the repository.

Related

With the gradle plugin in Eclipse, how can I get project dependencies like maven?

I'm looking into migrating some of our ancient maven projects over to gradle (so shiny). Things are looking pretty good however I'm unable to get Eclipse/Gradle to adjust the project dependencies appropriately when I have 2 projects checked out. I'm hoping to use a repo for standard jar dependencies but be able to depend directly on a project if it is checked out.
Let's say ProjectB depends on ProjectA. As far as I understand the Eclipse/Maven plugin, it is able to a:
Interrogate the maven dependency for ProjectA and understand its group/artifact/version tuple.
Look through ProjectA eclipse project (if imported) to see if has the same group/artifact/version.
Replace the jar dependency with a project dependency.
This is a powerful feature because it means that a developer does not need to import ProjectA when they are working on ProjectB -- they just get it from the repo. But if they do have it imported, they can make a refactor to ProjectA in Eclipse and it will automagically refactor the dependent code in ProjectB.
How can I get eclipse/gradle to adjust the build-path so that there is a project dependency when available otherwise use the jar?
Things I've looked into:
Gradle "multi-projects" but our code isn't in a hierarchy like that.
Gradle includeFlat but this isn't some simple single directory structure.
resolutionStrategy.dependencySubstitution but I couldn't seem to get it to work. I doubt that findProject(...) is able to find a project that is loaded into Eclipse to it can link the 2 projects together in the classpath.
composite builds seem to use some of the language I'm looking for but it is about importing a build into another build.
Anyone else figured this out? Thanks much in advance.

Importing multimodule maven project from Git into Eclipse/STS

I have been desperately trying to import a multimodule maven project from GIT into my (freshly installed) STS 3.9.4.
During the last hours I tried lots of solutions that were posted on stack overflow, but none of them worked for me.
These are the steps I did:
git cloned the repo from the command line (intentionally, because it didn't work either when I used the GIT integration of STS)
imported the project via File / Import / Maven / Existing Maven Projects
After the project was imported, it looks like this:
(please ignore the red icon at the top left, the problems persists even when this icon is not there)
I can Run As / Maven Install any pom.xml, but when I try to edit java sourcecode Eclipse tells me The resource is not on the build path of a Java project.
To fix this I tried:
convert to faceted form
added Java nature
Configure Build Path / Set as source folder
add buildcommand org.eclipse.jdt.core.javabuilder to .project
Being able to build is fine, but editing sourcecode without support for Organize Imports, Format Source, and so on is a real pain.
From your screenshot I assume the modules are nested within the directory of the reactor pom(=parent pom) and you have imported all of them as projects (reactor and modules).
Don't add a java builder to the "reactor" project.
Make sure not to open the java files from the projects corresponding to the reactor pom, but from src folder within the corresponding module projects.
The solution to this problem was somehow hidden, but in the end I have to say the reason was clear.
After I checked with a different multimodule project (https://github.com/Activiti/Activiti.git), I was sure that my STS and other components don't suffer from a generic problem. So the cause must be located in the project itself.
The multimodule project was setup correctly on the pom.xml level. But the topmost pom.xml was modified: most of the modules had been commented out:
The developer who introduced that change didn't experience any problems because he kept his already existing workspace. And the problem only occurs when a new workspace gets created and maven scans the pom files.

How do I get my Eclipse-Maven project to automatically update its classpath when I change a dependency in my pom.xml file?

I’m using Eclipse Mars with Maven (v 3.3). When I update a dependency in my pom (change the version), my Eclipse-Maven project doesn’t pick it up, even when I right click my project, and select “Maven” -> “Update Project.” I know this because I do not see compilation errors in the Eclipse Java editor that I see when I build the project on the command line using
mvn clean install
When I remove the project from the workspace and re-import it, then things get back to normal. However this is a cumbersome process. How do I get my Maven-Eclipse project to automatically detect changes in my pom and update the project libraries appropriately?
And yes, in the “Project” menu, “Build Automatically” is checked.
When you import the project into Eclipse, use Eclipse's own built-in Maven support (aka, m2e). I recommend against using mvn eclipse:eclipse as it doesn't give the best results (as you're seeing). Maven is a build and dependency management tool, not an IDE; expecting it to manage IDE-specific stuff is silly, in my opinion (I realize the Maven team thinks differently, that Maven should be responsible for managing your IDE, but that's nonsense).
So if you have the project available on your system, delete any Eclipse-specific files (typically just .classpath, .project, and folder .settings), they were generated by mvn eclipse:eclipse and you don't want them interfering with the "proper" import process described here. Then inside Eclipse, use File > Import > Maven > Existing Maven Projects to import the project. That should result in better integration between Eclipse and maven, including automatically updating the Eclipse build path when the pom is changed.
As a quick check, after doing the import that way, you should see a group called Maven Dependencies in the Libraries tab of the project's Build Path (in Properties dialog). Like this:
If you want the Eclipse project configuration to be automatically updated every time the pom is changed, there's a (experimental) setting for that under Preferences > Maven. Be aware that doing so might not be desirable, though - as mentioned in this feature request, it's a somewhat lengthy process that touches a bunch of stuff in the Eclipse Project; doing that automatically on every pom.xml change could end up being more trouble than it's worth.
Three Mandatory checks you should do for automatic update in your classpath
Your Repository is not in-sync with your Eclipse IDE, Please check the below settings in your IDE.
Right Click your any POM.xml from your IDE and check for the Maven profile which should be auto-activated. Also offline and Force update check box shouldn't be enabled. Please refer the below image.
Always check for your user settings which should reflect your local maven settings.xml, as shown in the below figure.
After performing all these checks, refresh your Eclipse Work-space to get these changes reflected.
Eclipse should be updating your classpath. If it's not, that implies something is going wrong.
It's hard to say what the problem could be exactly without knowing more about your project's pom.xml. More information might be necessary to solve the issue, but I'll just make a stab in the dark:
Open the .project file in your project's root folder and check the ordering of builders and natures there. It might be possible that some other nature on the project is also causing maven2Nature to fail. Move maven nature up and see if that helps any.
Alternatively you might be thinking that Eclipse does not update your dependencies because it does not add some some error indicators in the project that should be there with new dependencies. If that's the case try cleaning the current project (project>clean...). Maven in Eclipse does not necessarily trigger a full rebuild when dependencies are updated.
If none of this works, closing/opening the project might solve the issue quicker than re-importing.
What you wrote, should work. Did you check this:
does "pure" mvn install from terminal see your changes in POM?
maybe some Maybe plugin is buggy, cached some dependencies in target, and mvn clean install is needed
you can run Eclipse in a new workspace, and import your project there, sometimes it helps in case of such strange problems
instead of importing Maven project to Eclipse via m2eclipse, you can try to create Eclipse files via the old mvn eclipse:eclipse and see what happens then
does it work well when you try to import your Maven project to other IDE, the free IntelliJ Community Edition for example?
As a last resort, you can delete your current Eclipse installation and install a new version. When you add several plugins, they might interfere with one another and create weird behavior. After you do that, do not import your Maven project into your workspace, but rather create a new one and copy and paste the files that you had.

Diffrence between importing an existing project into Eclipse VS adding a dependency

I need you help understanding nub stuff
What is the Difference between
1. Importing and existing project into Eclipse
2. Adding a dependency ?
The "difference" is that those two are completely different things.
If you import projects into the workspace, you can edit them. For example, you could create a project with Maven, generate Eclipse project files and then import it into Eclipse, or checkout an existing project from SVN or Git am import that one. You can not edit individual files in Eclipse; everything has to be part of a project.
If you add a dependency, you can use the things defined in that dependency in another project. Usually, that dependency would be a JAR file. You can add individual JAR files manually, or use other Programs like Maven aggregate the dependencies and add them to the project.
Also, you can add a project from the workspace as a dependency to another project (after importing both into the workspace). Compared to adding a JAR file as a dependency, this has the advantage that you can edit the one project and the changes will imediately be reflected in the second project that depends on the first one. This makes development much easier than generating a new JAR file from that project every time something changes.

How to make Intellij follow sbt GitHub dependencies?

I managed how to add github dependencies to my sbt project following the instructions in this link.
However, Intellij could not find the github dependencies.
After om-nom-nom sugestion, only Scala plugin is needed:
Installing the Scala plugin from a fresh idea install
Import project from external model -> SBT project
? use auto import ?
Register "unregistered Vcs root"
Set module SDK with your JDK folder and adopt it for the project
Write a main file and press ctrl+shift+F10
The step 4 is important because you won't need to keep the working copies of the sub-projects anymore.
Idea creates them inside ~/.IdeaIC13 folder.
This link talks about multi-root Projects and synchronous branch control.
ps. the SBT plugin somehow was disabled and ideia became cofused about a subproject with a (nested) subsubproject.