IntelliJ Maven is correctly generating maven local repository but not adding the dependencies - maven

Hi I am trying to port a mid sized Maven project to IntelliJ Idea 12 (from Eclipse).
There are around 30 different modules in the project.
I am running an MVN install on each module via IntelliJ lifecycle management.
The jars are being correctly generated, and deposited into my local repository directory. It is also correctly picking up the third party libraries.
However IntelliJ is sometimes requiring me to then add the generated jars to my classpath as a dependency. (It is not enough to simply say "Add Maven Dependency", I have to physically add the generated jar as a library.)
In other cases it works correctly. Not sure why it is not consistent.

Have you tried updating the local Maven repository in IntelliJ IDEA? You can do so by opening Preferences->Maven->Repositories, than select your local repository and click on 'Update'.

Related

Cannot every time use internet for downloading spring-boot-starter-parent-2.3.3.RELEASE.pom from central

Is there any mechanism that if i keep all the pom dependencies locally at some path that everytime it gets picked from that path when i run Spring Boot app from command line?
Example: Everytime i dont't want to donwload the pom dependencies from repository as below and want to keep somewhere locally for use.
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.3.3.RELEASE/spring-boot-starter-parent-2.3.3.RELEASE.pom
I feel your question is a bit strange because it describes the main feature of maven.
When building a project with maven, all the dependencies required by your project are downloaded into a local repository. Future builds won't download again those dependencies.
When running a springboot application using maven, the downloaded dependencies are provided to the application's classpath so they aren't downloaded again.
When running a packaged springboot application, the dependencies are already inserted in the springboot fat jar so they aren't downloaded again.
Another point, if you want to ensure maven does not download anything you can execute maven in "offline mode" using the following parameter "-o"

can't find my maven artifacts

I'm working in eclipse and I have a problem that I can't import my personal java libraries.
I created the libraries and 'installed' them into my local maven repo (using mvn install). This created a subdirectory related to the 'version' name that was in the POM file from when I ran the command. Which seemed fine.
So in this directory there where the usual jar files and other stuff.
When I released this file I manually changed the name of the version in the POM. going from 0.0.1-SNAPSHOT to 0.0.1-RELEASE
This seems to have worked as I would have expected.
However I can't seem to find import the new release jar.
Using the maven repositories browser in eclipse I can see that the new artifact is in the 'local' repository.
I try to add the dependency in the following methods:
Select the main project -> Maven -> add dependency.
This adds the dependency details into the pom but with a type value detail of <type>pom.lastUpdated</type>
Select the project pom.xml file -> Maven -> add dependency.
This time the artifact for the 0.0.1-RELEASE is greyed out I can select it, but I guess nothing is actually happening.
The original 0.0.1-SNAPSHOT it selectable, and if I use this I do not have a <type> detail in the pom.
I don't understand why there is a difference in the RELEASE and SNAPSHOT artifacts, as they have both been generated in the same way, and clearly they are both visible in the browser, the contents of the directory on disk are the same. The file names and contents are identical with the exception of the word RELEASE or SNAPSHOT.
I know that I can simply add in the RELEASE jar to my build path, but this seems to be a ridiculous thing to have to do if I intend to use maven (or do I need to do this).
I don't want to use an external repo for storing my artifacts, and I'm not too keen to go to the trouble of installing nexus (or similar) on my local machine (just because I've had trouble with it in the past).
What am I missing so as I can get my maven project to see my local repository and all its artifacts.
Thanks in advance.
David
ps I've already tried things such as mvn dependency:purge-local-repository which definitely pulled in / updated all the local jar dependencies.
So I've managed to work around my problem.
As such this solution is ridiculous, and breaks all the purpose of maven.
So I found (from running maven from the cli) that there was an error in the parent of the project I was attempting to use.
The parent was missing a direct link to the scm plugin (version error).
Once I solved this problem, I then returned to the sub project, and got a lot of errors from missing stuff from the parent.
Essentially it was not 'seeing' all the log4j dependencies.
The solution (well non-solution really).
Add all the log4j dependencies to the sub project.
Edit in SCM and surefire test plugins (as it also started to fail the test code due to missing junit).
So this is great.
I have to define all my dependencies on log4j and in my sub / child project's pom.xml file.
I also need to define them all in my parent's pom.
As it then still refused to run tests in my new project (that used the above as a dependency), and refused to find log4j also. I then decided to add all of these as dependencies for my current project.
Great.
I thought the whole point of maven was I could define my dependency on log4j in my my logging library that I use (which is the dependency), and then it would 'automagically' pull in all the required from this dependency.
Clearly not.
As stated at the start. This is NOT AN ANSWER it is a crazy work around.
My logging library that I use should be able to define its own requirement on a specific log4j version (such as moving from log4j to log4j2), and then when I include this as a maven dependency any change to the required dependency should be seen automatically.
But No : I have to import the dependency on log4j in my other projects also. So now if I had updated my logging library from log4j to log4j2 I would need to go to all my project that use this library and update their pom's to ensure that I have the correct version of log4j.
Seems the whole point of maven has just been lost!
Can someone please tell me where I am going wrong!
David.

IntelliJ uses snapshots with timestamps instead of -SNAPSHOT to build artifact

I have a project with snapshot dependencies. For simplification let's say that there is an project A which depends on library B-0.1-SNAPSHOT.
A depends on B
B resides within Nexus repository as a snapshot. I can see that it is stored with timestamp so the actual name in Nexus is something like: B-0.1-20141126.171716-67.jar
After executing:
mvn clean install -U
on project A, dependency B is downloaded from Nexus to my local repository. There I can find two jars of library B:
B-0.1-SNAPSHOT.jar
B-0.1-20141126.171716-67.jar
So far so good.
After maven build is complete I can see that B-0.1-SNAPSHOT.jar was taken to build A artifact (.war file)
I also have project A imported to IntelliJ as a maven project. There I run it on Tomcat. Project is build by IntelliJ and B-0.1-20141126.171716-67.jar is added to .war file.
At the end I have .war with both B-0.1-SNAPSHOT.jar and B-0.1-20141126.171716-67.jar within WEB-INF/lib directory.
For me is seems like a bug in IntelliJ because B-0.1-SNAPSHOT.jar should be taken from local maven repository... not the timespamped version. Is there any way to force IntelliJ to act propeply?
Maven version is 3.2.3, IntelliJ 14.0.1 (but the same behavior was on 13).
I was faced to the same problem today, and I found how to disable this feature.
F4 on your module, and go to artifacts then select the name of your artifact webapp:exploded and check the show contents radio at the bottom of the frame.
Go to WEB-INF/lib and search for your dependecy B-0.1-SNAPSHOT.jar and expand the line you will see a compile output folder in it, just remove it, then repackage and run, you will now only have the B-0.1-SNAPSHOT.jar and the one with the timestamp should be gone.
The downside of this is that you will have to make sure to mvn install your B module before running the A module within IntelliJ, because IntelliJ won't package your dependency and bundle it with the code you've just edited but not installed in your local maven repository.

Maven takes dependency from workspace and not from local repository

I have a web maven project in eclipse, one of its dependencies is a j2se maven project that I have in the same workspace. Something curious to me is that I believed that all dependencies declared in a maven project were taken from the remote repository or a local repository but its not, I mean; even I havent done a maven install to my j2se java project(so its not located in the local repository), when I create a war from the web project this jar is included.
I think this behaviour is because of eclipse and not maven and eclipse will always takes this dependency from the workspace
2 Because of this I can change the j2se project and not have to do a maven install ever to this project,
From the point of view of maven, I should do a maven install to my j2se project in order the web project takes the dependency from the repository and not from workspace, right?
Thanks
Yes, Eclipse m2e will by default try to resolve dependencies from the workspace. In case it's not present in the workspace, it will try to resolve it from the ArtifactRepositories(your local and remote repos).
In case you want to turn off the workspace resolution, you can do that by right clicking on the Project and selecting Maven.If you uncheck that check-box, the dependencies for that particular project won't be resolved from the workspace.

maven + elicpse related questions

Forgive me asking following questions. I am totally lost in regards to maven+eclipse. I checked out someone's java project (maven built) from SVN to my local eclipse (kepler). When I click Windows > Preferences, I see Maven.
question 1)
Is this a maven plugin? When developers say maven in eclipse, are they referring to maven plugin? maven and maven plugin are two separate components?
question 2)
when I click on user settings, C:\Users\myName.m2\settings.xml is missing. Exact error message is "User settings file doesn't exist". Does it get created when you install maven plugin at first time?
question 3)
I found three folders may have to do with maven C:\workspace\maven_local_repo_artifactory directory, C:\maven_local_repo and C:\Users\myName.m2\respository but not sure how they get created and what is the relationship among them.
question 4)
Is it ok to remove current maven plugin from eclipse and re-install it then check out the java project from SVN? I think my maven or maven plugin settings are not correct in my local box.
1) Is this a maven plugin? When developers say maven in eclipse, are
they referring to maven plugin? maven and maven plugin are two
separate components?
Yes. This is the maven-plugin. maven-plugin uses the configurations of maven (%M2_HOME%/conf).
If you wanna work with maven, you need to install it on your machine. Then you can run maven commmands. In addition, if you want to invoke maven commands within eclipse (conveniently) - you can install the eclipse-plugin. "maven-plugin" is a plugin for eclipse, that lets you use maven within Eclipse conveniently.
2) when I click on user settings, C:\Users\myName.m2\settings.xml is
missing. Exact error message is "User settings file doesn't exist".
Does it get created when you install maven plugin at first time?
By default, the maven-plugin assumes that your settings.xml (which is the configuration file of maven) is in the path you have mentioned. However, there are cases (like in my case) where the config file is not there, but under %M2_HOME%/conf. you can update it in Eclipse, and the error will disappear.
3) I found three folders may have to do with maven
C:\workspace\maven_local_repo_artifactory directory,
C:\maven_local_repo and C:\Users\myName.m2\respository but not sure
how they get created and what is the relationship among them.
C:\Users\myName.m2\respository is the "local repository". If you learned a bit about how maven works, it holds a local repo on the local machine, and it keeps there all artifacts. It downloads them from the "repository" - if you have one in your company (Nexus, Artifactory, etc) or from Maven Central. However, this path is configurable by Maven's settings. So there might be that someone played with it and changed the path, and these other directories were created. You did not mention what resides inside these paths...
4) Is it ok to remove current maven plugin from eclipse and re-install
it then check out the java project from SVN? I think my maven or maven
plugin settings are not correct in my local box.
Sure it is OK. You may remove the plugin, and the source plus maven itself will not be deleted from your machine.
HTH.

Resources