Kevin's Worklog

Documenting the Daily Stream

Including SNAPSHOT Dependencies in Maven Build

I try to not use SNAPSHOT dependencies in Maven but sometimes, as code is in process, I need to temporarily reference a SNAPSHOT dependency. If that SNAPSHOT dependency is in my local Maven repository, my local build will work. But, when the project gets built in another environment (like Travis-CI’s), the build fails. To work around this, the project needs to be aware of how to resolve those SNAPSHOT dependencies.

To accomplish this, add repositories (and pluginRepositories if the SNAPSHOT is also a plugin) to the project’s pom.xml file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<repositories>
  <repository>
    <id>dependency-snapshots-repo</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    <releases>
      <enabled>false</enabled>
    </releases>
    <snapshots>
      <enabled>true</enabled>
    </snapshots>
  </repository>
</repositories>
<pluginRepositories>
  <pluginRepository>
    <id>plugin-snapshots-repo</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    <releases>
      <enabled>false</enabled>
    </releases>
    <snapshots>
      <enabled>true</enabled>
    </snapshots>
  </pluginRepository>
</pluginRepositories>

With these two elements added, the Travis build will be able to resolve the SNAPSHOT dependencies. The elements can be removed again once the SNAPSHOT dependencies are replaced with stable versions.