views:

276

answers:

2

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?

+1  A: 

Chris, 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.

EDIT: 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

peakit
Nope. There is no src/main/filters.
Chris Conway
Check the edits.. I think `mvn dependency:tree` might help you zero in on the artifact bringing 2.1.1
peakit
Actually `mvn dependency:tree` fails because of the "missing" dependency.
Chris Conway
Chris, just to troubleshoot we need to figure it out who is bringing this jar to your project. So, I would suggest point everything to the old set up of 2.1.1 and try to get the `mvn dependency:tree` running (u may need to install some old dummy jar as 2.1.1 to local repo). As then we will get clear idea which artifact has dependency on 2.1.1.
peakit
I'll be damned. I copied `foo-2.2.0.jar` to `foo-2.1.1.jar` and ran `mvn dependency:tree`. It returned the resolved dependency `com.example:foo:2.2.0:system`. I deleted `foo-2.1.1.jar`. No more dependency failure. If you want to write this up as a workaround, I'll accept your answer.
Chris Conway
Good to know that it finally worked!
peakit
A: 

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.

Stephen C
I ran `mvn clean` about a million times.
Chris Conway