Reputation: 2726
Say I have written a library and put it on Sonatype's snapshot repository. Suppose the groupId
is my.group
, the artifactId
is my_lib
, and version
is 0.0.1-SNAPSHOT
.
With the SBT build tool, one can simply add the following line to build.sbt
to enable adding dependencies from Sonatype's snapshot repository:
resolvers += Resolver.sonatypeRepo("snapshots")
And then I can freely add, after this line, the following line:
libraryDependencies += "my.group" %% "my_lib" % "0.0.1-SNAPSHOT"
How do I do this in Maven? Obviously, I cannot just add the following:
<dependency>
<groupId> my.group </groupId>
<artifactId> my_lib </artifactId>
<version> 0.0.1-SNAPSHOT </version>
</dependency>
because this library is not published on Maven Central Repository. What else needs to be added?
Upvotes: 2
Views: 587
Reputation: 137164
You can add repositories to your POM by using the <repositories>
element, under <project>
. This can also be added inside settings.xml
if you want to add it globally. If your library is published on Sonatype snapshot repository, you can add it like this:
<repositories>
<repository>
<id>sonatypeSnapshots</id>
<name>Sonatype Snapshots</name>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
This configures a new repository that is enabled for snapshots but disabled for releases. Maven will look at this repository only to resolve snapshot dependencies.
With this declaration, you can then add your dependency like you did.
Upvotes: 3