This question is a little different than the other “checking for latest dependency version” type questions.
Let’s say we have a project, DepProjA
, that builds and publishes an artifact for our other Java apps to import as a dependency. For example, AppProj1
lists DepProjA
as a dependency in its pom.xml file.
<dependency> <groupId>com.mycompany.depproj</groupId> <artifactId>depproja-lib</artifactId> <version>feature-addthisfeature</version> </dependency>
As you may notice, DepProjA, publishes “feature” versions of this JAR with the version named after the working branch name. This is so that other teams can test these particular feature updates before they are published as an official version update. If a bug is found and the fix is pushed under the same branch, the “feature” artifact is updated. However,when we rebuild AppProj1
to try and pull and utilize that latest artifact, it seems to be using the previous local version instead.
Is there an option, either in the pom.xml, or the mvn CLI options, so that maven will always pull down the latest artifact instead of using whatever version is cached? I know I can do a “blanket approach” like purging cache and such, but looking for something that targets specific dependencies. Kind of similar with Docker images where the tag itself won’t change, but the underlying SHA can be updated when a new version of that tag is published.
An alternate idea I don’t even know is possible: When publishing an artifact, is there a way to add custom metadata or labels that I could then reference? For example, I add a “cicdlabel” that could reference the pipeline ID that published the latest version. Then, I could change that in the application’s dependency info when I know there is a change:
<dependency> <groupId>com.mycompany.myproject</groupId> <artifactId>myproject-lib</artifactId> <version>feature-addthisfeature</version> <cicdlabel>12345</cicdlabel> </dependency>
Advertisement
Answer
In Maven by design released artifacts are immutable. You can not update the same release version of artifact in Maven central.
It ensure that your build is reproducible, when we change content of released artifact the same build can break in the future.
In your case you should use SNAPSHOT
versions for your artifact, and SNAPSHOT
version can be updated.
You can use updatePolicy for your repository configuration in your settings.xml.
Yo can use mvn -U ..
for update SNAPSHOT
versions on every build.