My Maven project has a dependency on a non-Maven library, which is coded as a system dependency:
<dependency>
<groupId>com.example</groupId>
<artifactId>foo</artifactId>
<version>${foo.version}</version>
<scope>system</scope>
<systemPath>${foo.jar}</systemPath>
</dependency>
where the location of the library can be controlled via local properties:
<properties>
<foo.version>2.1.1</foo.version>
<foo.basedir>/usr/local</foo.basedir>
<foo.libdir>${foo.basedir}/lib</foo.libdir>
<foo.jar>${foo.basedir}/java/foo-${foo.version}.jar</foo.jar>
</properties>
Recently, the library switched from version 2.1.1 to version 2.2.0, so I changed the foo.version property, but Maven seems to be stuck on the old version:
...
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) com.example:foo:jar:2.1.1
...
I have run mvn dependency:purge-local-repository (many times, actually). The string 2.1.1 does not appear anywhere in my POM, profiles.xml, or settings.xml. Still, every time I try to build my project, Maven fails with the above error.
What's going on here? Where is Maven storing the dependency version information and how can I update it?
I think the ${foo.version} might be getting resolved as a filter property. Can you check the properties file under src/main/filters.
Not sure if this is indeed the problem but just give it a try and update back.
The other reason that I could think of is - there might be a transitive dependency on com.example:foo:jar:2.1.1. That is some other dependency which needs 2.1.1 version of this artifact. You can find which artifact is bringing this transitively by doing mvn dependency:tree
You know what. Seeing the workaround that #Chris Conway found, I think that this might have been "solved" by simply running mvn clean.
And even if it would not have helped here, it is always worth trying mvn clean when something strange happens.
Dependency version conflict is a very common problem and most of the time when we start building our application, we never focus or generally we forgot on that aspect until and unless our application starts behaving in an unexpected way or getting started some exception.
For readers and visitors of SO who are interested in knowing the reason why dependency conflicts arises and how we can avoid them in our application , I found a source here explained in a precise way ,so i thought of adding my 2 bits to it .
http://techidiocy.com/maven-dependency-version-conflict-problem-and-resolution/
Cheers
Related
I am trying to move from JDK 8 --> JDK 11 and sure enough maven surefire-plugin is failing. So I know that I need to change it's version to 2.21.0 or above that and I already did so. The version is only referenced in one pom so everything should be fine and even intellIJ says that I am using version 2.22.2.
The thing is I am when I run a mvn clean install -U or mvn test, or a mvn clean then mvn compile-test and lastly a test I am still getting error referencing:
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test (default-test) on project modular-index-composer: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test failed.: NullPointerException
How is it even possible? I am 100% sure that the project must have a version of 2.22.2. Is there any other way where it could be set?
Kinda obvious/dumb solution:
So the project is made up of multiple modules, and there is a "parent" module that has most of the dependencies with their versions. I changed the sunfire version in this modules pom, and nothing seemed to be changing. (Eventhough intellij showed the correct newer version for the plugin)
So I decided to just exclude the parent pom and add the sunfire plugin with its version directly into my module. And behold it worked.
The issue is probably something with the parent pom, my guess would be that my module is not pulling from the correct parent pom version or it mixed it up somehow.
I am trying to upgrade a project from JDK 7 to JDK 8.
In order to fix some issues during compile time, I needed to upgrade Maven to 3.6.3 as well.
The other issue is fixed with this upgrade however, I am getting the below error during mvn install
Failed to execute goal on project jbossha-PATCH: Could not resolve dependencies for project com.company.wae:jbossha-PATCH:jar:5.1.0.GA: Could not find artifact sun-jaxb:jaxb-api:jar:2.2 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
When I check my m2 repo, the jax-api.jar is present under sun-jaxb folder. If I delete sun-jaxb, it is created again with jax-api.jar.
This dependency is present in a lot pom.xml within the project.
Why the error is saying that it can not find the artifact and is there a way to solve this issue?
Why the error is saying that it can not find the artifact and is there a way to solve this issue?
Because the dependency in the POM files is incorrect. I checked, and there are no official dependencies for "sun-jaxb" in Maven Central.
The correct Maven dependency for the JAXB apis in Java 8 is
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.8</version>
<scope>provided</scope>
</dependency>
as described in "https://stackoverflow.com/questions/63608553". I checked and the artifact is there, as are older and newer versions.
So a good solution would be to update all of the POM dependencies.
Now I presume that you are trying to build was building correctly before you started porting it. (Did you check?) If it was, then it must having been getting the "sun-jaxb:jaxb-api:jar:2.2" dependency from ... somewhere:
It might have been in Maven Central "unofficially" and removed as a result of a clean-up
You (or the previous maintainer) might have installed it directly into the local repo on your build box.
You might have been getting it from another repo; e.g. a corporate Maven repo where someone has previously uploaded it.
It would be a good idea to figure out how it worked before.
I have a .jar file, which I want to use in my current project which I am building with Maven. After some research I figured out that I need to install it locally. This I did using:
mvn install:install-file -Dfile="D:\Eclipse Workspace\TextOnlyJam\adapterLib\lwjgladapter.jar" -DgroupId=lwjgladapter -DartifactId=lwjgladapter -Dversion=1.0 -Dpackaging=jar`
I then added the dependency into my pom like so:
<dependency>
<groupId>lwjgladapter</groupId>
<artifactId>lwjgladapter</artifactId>
<version>1.0</version>
</dependency>
My project in exclipse now manages to resolve all dependencies and does not give me any compile errors. However after cleaning and updating my maven project several times, I still get the following error when running an install:
Failure to find lwjgladapter:lwjgladapter:jar:1.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
I assume that maven is looking for the artifact in the wrong location, however I can not figure out what I need to change here.
(I am also not sure if I need to add the dependency into , since it does not seem to change anything when I do.)
Okay, I just figured out that it was just a stupid mistake on my end. I looked into the repository folder and found, that my jar file was named `.jar``
So yeah, a simple copy and past error. Thanks for the help so far!
Here is the situation :
I want to use a locally installed jar in a springboot project. I included the dependency to this artifact in my pom.xml :
<dependency>
<groupId>org.mycie.myjar</groupId>
<artifactId>myjar</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
This jar uses the artifact snakeyaml with version 1.16
But in my main project, Springboot uses snakeyaml version 1.23
The concurrency seems to cause some issues when running the application.
Do you have any idea on the good practices to tackle this issue?
Maven will only let one of the jars into the resulting application. You can find out by calling mvn dependency:list which jar Maven chose.
The resulting problem cannot be really solved by Maven. Instead, you need to figure out which version of snakeyaml works for all scenarios. Since one of the jars belongs to you, it is probably best to just update the dependency of myjar to avoid this problem.
We have multi module environment where in we have lot of poms that uses numerous dependencies.
1) How to see which dependency in our pom causing a specific jar to download into repository.
Eg : I have commons-lang3 in all my poms .But some included dependency in pom's is downloading older jars into my repo which I need to avoid.I did
mvn dependency:tree but this didn't helped me.
Since my application is a mammoth its very difficult to go and see all the dependencies that are included.
Is there any way we can check which included dependency is causing older
versions of jar to download
Any one who can shed some light would be appreciated.
Thanks
Praveen
This is a bit crazy, you're right but I still use most often:
mvn dependency:tree -Dverbose
It's even crazier to read than the normal you mentioned. I do, however, agree with JF Meier here, dumping it into a text file is the way to go.
You can also search for certain things:
mvn dependency:tree -Dverbose -Dincludes=project-c
Sometimes to get a cleaner picture though I use
mvn clean dependency:tree -DskipTest
Got these when solving another problem from here.
If you want to know where a dependency comes from, use dependency:tree. I do not understand why it did not help you. Dump the result to a Text file and search for the artifacts you are interested in. Then you will immediately see where they come from.
If you want to set the version of a given dependency, use <dependencyManagement> to set the version to the one you like.
There are, of course, dependencies in your local repository which are not dependencies of your project, but are dependencies of Maven plugins.