Maven takes dependency from workspace and not from local repository - maven

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.

Related

How non maven project can be added as a dependency in maven project

One project A is added in project B as a source.
I want to add in POM.xml of project B.
1-A is non maven project.
2-B is Maven project
How non maven project can be added as a dependency in maven project as a dependency.And I don't want to run it as a separate project and place the jar in local repository.
You need to put the "non-maven-jar" into the local (or a remote) repository. You can either build it and use mvn install:install-file to install it locally (or the deploy plugin to use a remote repository) or you need to change project A into a Maven project.
Technically, it is also possible to include a dependency by a path (<systemPath>), but this is not recommended.

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.

How to remove maven artifcat completely from SpringSource?

I have a local maven repository and installed a custom artifact. It works if i reference it in other projects. But now i want to use a server for a "own maven repository". If i delete the artifact from the local maven repository, i assumed that the project will not build when i do a maven clean and maven force update dependencies. The artifact cannot be found under .m2/ but Spring Source Tool Suite still can add the artifact to new Java Projects. Create New Java Project -> Edit Pom -> Maven Artifact is added, even if i deleted it from local repository .m2/ . How is this possible and how can i delete it completely, to be able to test if now all dependencies are updated from my server with the .m2/settings.xml configuration?
Your repository is just a directory/file structure. Go to your local repo, find the path (the group id is the path), and delete from the place where you start to see version numbers. When you rebuild, the artifact should be downloaded/replaced from your server/repo.

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

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'.

Maven beginner question, get m2eclipse to download jar and add to build path?

From what I have read, after adding the relevant maven repositories, maven should automatically download the necessary jars to satisfy dependencies in the pom.xml file.
However, no jars ever get downloaded for me after I add dependencies in eclipse. Am I missing some glaringly obvious step?
I'd recommend to start from creating your project with m2eclipse. See more details in this article.
Basically, you need to make sure the following:
your Eclipse project has a valid pom.xml and all dependencies are available (you should see errors on Maven console, in the Problems or Markers view or when opening pom.xml in m2eclipse's POM editor)
Maven support is enabled for this project (you can use Maven / Enable Dependency Management from popup menu on that project)
project configuration is in sync with pom.xml (you can use Maven / Update Project Configuration from the project popup menu)
you can also use Maven / Update Dependencies to refresh your dependencies (e.g. when you got them in your Local Maven repo from the command line)
Dependencies jars aren't in your project but in your local maven repository.
These jars will be automatically used when you compile you project with maven (or m2eclipse).
If you don't have the needed jar yet, maven will download it for you.

Resources