I have a maven project and I have created a new external jar called myjar. I subsequently updated my pom to myjar.17.1.snaphot from myjar.17.snaphot. In my external libraries, I do not see this jar - I still see myjar.17.snaphot. Therefore, Intellij cannot compile my code.
Whe I do a maven install at the command line, all works fine. Why doesn't intelliJ update my jar?
<dependency>
<groupId>com.me</groupId>
<artifactId>myjar</artifactId>
<version>17.1-SNAPSHOT</version>
</dependency
IntelliJ can not be aware of a change to an external dependency. When you change your version in an external dependency, there is no JAR installed into your local repo ($HOME/.m2). Once you do mvn install there is a file in this dir, IntelliJ notices it and adds it as a dependency.
A possible workaround is to add this external dependency to a parent pom as a module of your project.
EDIT
After installing you also need to update all references in your project poms to the new snapshot version, then right click on the pom.xml in Idea -> Maven -> Reimport.
Related
I am currently using Intellij Idea 2020.2.4.
I want to replace a dependency with a newer version of itself.
I replaced
<dependency>
<groupId>com.company.digital.fmk</groupId>
<artifactId>dgt-security</artifactId>
<version>2.6.24</version>
</dependency>
with
<dependency>
<groupId>com.company.digital.fmk</groupId>
<artifactId>dgt-security</artifactId>
<version>3.9.0</version>
</dependency>
I've checked that in the effective pom, the version has changed to the new value. However, after running
mvn -U clean install, when I click on a class from the dependency, it still shows the old version.
When I try to delete the old version from the project structure, it says that it is still used in a module, even though I can't find the old version number anywhere in the project.
I can't manually delete the old library from my local folder, because it is used in another project.
Other answers have suggested using Maven -> Reimport, but I didn't find this in my intellij
What can I do to make intellij use the new dependency version in my project ?
EDIT
When I right-click on a project and select Maven, here are my options:
Reload project (already tried, did not work)
Generate sources and update folders
Ignore projects
Unlink maven projects
Open 'settings.xml'
Create 'profiles.xml'
Download sources
Download documentation
Download sources and documentation
Show effective pom
Show diagram
Show diagram popup
You can go to your Maven repository:
.m2/com/company/digital/fmk
Delete jar files
Rerun command, it will download dependencies again.
Right click on project -> maven -> sync shall do the trick
previous versions did this by default on changes in pom.xml
now it seems to be not available anymore
I have the current version of the dependency successfully installed in the local mvn .m2 registry with mvn clean install (confirmed by cd into .m2 repository).
I then modified the pom.xml of the project to include the new version number:
<dependency>
<groupId>com.xyz.lib</groupId>
<artifactId>xyz-lib-abc-model</artifactId>
<version>1.4.0-SNAPSHOT</version>
</dependency>
Maven was able to build successfully with 1.4.0-SNAPSHOT, but when I accessed the project in IntelliJ, it linked to an old version (0.1.1-SNAPSHOT) instead of the current version.
When I checked the dependency tree using `mvn dependency:tree, I have:
[INFO] +- com.xyz.lib:xyz-lib-abc-model:jar:1.4.0-SNAPSHOT:compile
Which looks correct to me.
I have tried using <dependencyManagement> but then it makes the project failed to build, and failed to detect the model.
Anyone knows what's going on and how to get maven to pull the correct version?
Thank you in advance!
Try re-importing the dependencies from local m2 in IntelliJ like :
Open the project view in IntelliJ
Right click the pom.xml file and
select Maven - Reimport If this works for you IntelliJ will add the
dependencies to the project
Check the if the dependencies you need are added in File - Project
Structure - Project Settings - Libraries and File - Project
Structure - Modules - Dependencies
I have seen this issue with IntelliJ.
If you don't need the old version anymore, you can cd to .m2 directory and delete the older version manually.
But you need to keep the both versions, you can open the project as a fresh project using the pom.xml. This will solve the issue.
Try the following approach:
Close the project in IntelliJ
File --> Open ...
Find pom.xml of your project, not the idea project files
Open this pom.xml. It will re-build all the dependency model in accordance with the information found in this new pom.xml (that I assume doesn't have an old dependency anymore).
DependencyManagement section is irrelevant in this case - mention it because you've said in the question that you've tried this - so don't bother, it will save you some time :)
my first guess goes to the used maven type in your IDEA is not the one that you use in the terminal. :)
You can set up the installed maven instead of the bundled one.
Or another solution is that you proceed a “refresh/reimport” in pom.xml. It will investigate the classpath based on your pom.xml and refresh the ones that needed.
You should see the "Reimport button here
If you don't see Maven at all, that means. you haven't added your project to IDEA as a Maven project.
Please then do the following
1. Right Click on pom.xml
2. 2. Add as a maven project
I have a maven project in Eclipse and I added some local jar files to the buildpath. If I do not add any dependency to the pom.xml file I am able to execute maven install. Then, if I add those dependencies to the pom the command maven install continues working as well. Now in this situation if I run maven clean then maven install fails. Why?
I also tried to run Maven -> Update Project but the result is the same. What is the problem?
If you are using non maven dependencies then it will fail to build eg from CLI and in your case in Elipse after cleaning the project as well. In order to make it work you have to installl tha JAR you are using as Maven artifact and the ninclude it in POM dependencies like every other library.
Here you have info on how to install 3rd party JARs to local repo
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
I got the same problem and resolved by adding the 3rd party in the pom.xml manually
I want to use cplex through a maven project. when I use cplex in a non-maven eclipse project, it runs correctly. in non-maven project I had to add the path to native library location of cplex in java build path.
but in the maven project, I get errors like "java.lang.NoClassDefFoundError: ilog/concert/IloNumExpr" at runtime.
I add dependencies to my cplex.jar in pom :
<dependency>
<groupId>cplex</groupId>
<artifactId>cplex</artifactId>
<version>2.0.1</version>
<scope>system</scope>
<systemPath>${basedir}\IBM.ILOG.CPLEX.Optimizer\cplex\lib\cplex.jar</systemPath>
</dependency>
and I test to add native libraries to src/main/resources, and adding resource tab in pom: it doesn't work. I add the native library to class path environment variable: it doesn't work. I copy them in c:/windows/system32: it doesn't work!
can any body help me? what is the solution? :-(
Just go through
How do I add a jar file to my local Maven repository using Eclipse m2e on Luna Service (4.4.1)?
basically if its a jar not available in maven repository, you can still add it to your local repository and with the required group id, artifact id, and other parameters and use the scope as system while referring to it from you pom file.
I have added dependencies in pom.xml and immediately the corresponding jars started to show up in maven dependencies section of dynamic web project.
I just want to know that I have not done mvn install in cmd so how did they get saved in maven repository.
Another query I have, is that since jars are availble in maven dependencies folder of dynamic wep project, so my project runs successfully or not as depndencies are already satisfied without doing mvn install.
When you list a <dependency> in your project's POM, M2Eclipse (Eclipse's plugin in this case) will trigger Maven to resolve that declared dependency...meaning Maven will check your local repo first for that dependency, and if it's not found there it will pull it down from the next highest repo you have configured (possibly an agency-level repo, or Maven's default public repo on the web).
No mvn install is required, as the purpose of that would be to install your current project's packaged artifact into your local repo, rather than install any dependency.
Hope this helps to clarify why an install is not used to copy dependencies into your local repo.