Kousha
Kousha

Reputation: 36219

Best way to "mvn link" a dependency?

Let's say I have two projects on my machine, ProjectA and ProjectB; ProjectB uses ProjectA as a dependency.

I publish both of these packages separately as well. Now I want to develop locally, make changes to A but test is in B. How do I "link" ProjectA locally in ProjectB so that when I run ProjectB, it is using the local ProjectA and not the published package?

Upvotes: 0

Views: 306

Answers (1)

Glains
Glains

Reputation: 2863

First of all, when referencing maven dependencies, you can use a fixed version number like 5.2.0 or a SNAPHOT-version like 5.2.0-SNAPSHOT , which has the semantics as being currently in development or work in progress. Also, those versions are associated with an update timestamp in the repository to decide which SNAPHOT version is the newest.

Project A:

  • Change the version in the root .pom to a SNAPHOT-version. (In multi-module projects, you can use [1] instead to not change every version manually.)
  • Run mvn install your artifact to the local maven repository.

Project B:

  • Reference the newly installed SNAPSHOT-version for project A in the dependencies section.
  • Run mvn compile and the new version will be used.

Remember that releases sould not contain references to snaphot versions. To automate this process (of changing back an forth between snapshot and release), you can use [2].

[1] Versions Maven Plugin

  • Use mvn versions:set -DnewVersion=your_new_version to change a version.
  • Then use mvn versions:commit or mvn versions:rollback respecively.

[2] Maven Release Plugin

Upvotes: 1

Related Questions