31

Our internal repository (Artifactory) now contains both the stable builds as well as SNAPSHOT versions of our internal libraries.

For stable builds there has never been a problem of downloading anything from the repository.

However, when I add a -SNAPSHOT, Maven claims to be unable to find the dependency, even though it is most definitely in the repository.

If I build and deploy the dependency locally (i.e. into my local repo) all works normally.

Basically, this works:

<dependency>
  <groupId>com.example</groupId>
  <artifactId>ourlibrary</artifactId>
  <version>1.0.0</version>
</dependency>

and this doesn't:

<dependency>
  <groupId>com.example</groupId>
  <artifactId>ourlibrary</artifactId>
  <version>1.0.1-SNAPSHOT</version>
</dependency>

Even though both versions were built the same way and deployed (as far as I can possibly tell) correctly to the repository.

The error:

Missing:
----------

1) com.example:ourlibrary:jar:1.0.1-SNAPSHOT,

  Try downloading the file manually from the project website.

  Then, install it using the command:
      mvn install:install-file -DgroupId=com.example -DartifactId=ourlibrary -Dversion=1.0.1-SNAPSHOT, -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there:
      mvn deploy:deploy-file -DgroupId=com.example -DartifactId=ourlibrary -Dversion=1.0.1-SNAPSHOT, -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency:
        1) com.example:product:war:2.0.0-SNAPSHOT
        2) com.example:ourlibrary:jar:1.0.1-SNAPSHOT,

While this sounds similar to this question, the resolution arrived at there does not apply to my case.

Any insights into this issue would be greatly appreciated.

Edit

Running with -X (as John V. suggested) revealed the following:

[DEBUG] Skipping disabled repository central
[DEBUG] ourlibrary: using locally installed snapshot
[DEBUG] Skipping disabled repository central
[DEBUG] Using mirror: http://repo.example.com/repo (id: repo.example.com)
[DEBUG] Artifact not found - using stub model: Unable to download the artifact from any repository

  com.example:ourlibrary:pom:1.0.1-SNAPSHOT

from the specified remote repositories:
  repo.example.com (http://repo.example.com/repo)


[DEBUG] Using defaults for missing POM com.example:ourlibrary:pom:1.0.1-SNAPSHOT:compile
[DEBUG]   com.example:ourlibrary:jar:1.0.1-SNAPSHOT:compile (selected for compile)
Community
  • 1
  • 1
Kris
  • 14,426
  • 7
  • 55
  • 65

2 Answers2

15

Two thoughts come to mind:

  1. The path structure in your internal repository for your artifact is incorrect. I suggest running the maven command with -X parameter. It will display the maven's attempt at downloading the files. Get the line that has your repository as the url and try and look for it yourself.

    The path should look like

    /com/example/ourlibrary/1.0.1/ourlibrary-1.0.1-SNAPSHOT.jar

  2. You didnt include your repository as a repository in your pom.xml
John Vint
  • 39,695
  • 7
  • 78
  • 108
  • 2
    I did not declare the repo in the POM, but rather specified in the maven settings that our repo was a universal (*) mirror. Shouldn't that be sufficient (it certainly is enough for the stable builds)? Adding an explicit declaration to the POM does seem to resolve the issue. – Kris Nov 04 '10 at 14:51
  • I unfortunately haven't done too much work with the settings.xml for repositories. I included them in a parent pom, so any developer starting fresh needs not worry about the settings.xml in case the repository has to change (which it actually has for us) – John Vint Nov 04 '10 at 14:55
  • 16
    I think I've reasoned this out. For stable builds, Maven will default to 'central' which my mirror settings redirects to our repository. For SNAPSHOT builds there is no default (as central doesn't handle them) and in the absence of the POM specifying a repo (that *does* handle SNAPSHOT builds), it will simply fail without even trying to look it up. – Kris Nov 04 '10 at 15:02
13

Typically you have a separate snapshots url from releases url. Just different paths in the same repository, but listed as separate repositories in the pom. The one for snapshots needs to have snapshots enabled, and the one for releases has snapshots disabled:

<repositories>
        <repository>
            <id>central</id>
            <url>
                http://<releases-url>
            </url>
            **<snapshots>
                <enabled>false</enabled>
            </snapshots>**
        </repository>

        <repository>
            <id>snapshots</id>
            <url>
                http://<snapshots-url>
            </url>
            <snapshots>
                **<enabled>true</enabled>**
                <!-- never, daily, interval:X (where X is in minutes) or always -->
                <!--<updatePolicy>daily</updatePolicy> -->
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
    </repositories>
kevinmrohr
  • 821
  • 7
  • 11
  • 1
    This works although you should note that this goes under the profiles section of the Maven settings.xml file. – Kris Nov 09 '10 at 08:29
  • We keep it in our master/parent pom file that all of our projects inherit from. This way developers don't have to configure this in their settings.xml files. Settings.xml is primarily for stuff that is machine or user specific, and all of the developers for a project should typically be using the same repository. While you can put repositories in the settings.xml file, I would think that would be an exception case, and not the norm. – kevinmrohr Nov 09 '10 at 23:15
  • 1
    Very strange, that I can deploy snapshots without this, but it's not possible to download deployed shapshots. Profile setup works fine. – Betlista Sep 25 '13 at 14:47
  • @Kris this still downloaded off the apache.org central until I added tags for a mirror of everything pointing to the releases URL and a mirror of snapshots pointing to the snapshots URL as found by trial and error by Raghuram, http://stackoverflow.com/a/7430640/80772 – eel ghEEz Jan 13 '17 at 03:08
  • @Betlista The 'repositories' tag section controls dependencies pulled down to your build. Artifacts you build and deploy go to where 'the distributionManagement' tag section tells them to go. – Lee Meador Oct 03 '18 at 22:27