Is there a way to make Maven download snapshot versions automatically?

前端 未结 7 760
灰色年华
灰色年华 2021-02-05 08:27

So I have a project that depends on a snapshot version of another project. The dependency is:


  org.oop
  

        
相关标签:
7条回答
  • 2021-02-05 08:51

    Does that dependency exists in your repository? (in pom.xml or settings.xml)?

    Looks like not. By the way, take a look at your config, just you are not using -o (offline). Also you can use -U to refresh snapshots.

    0 讨论(0)
  • 2021-02-05 08:54

    To update snapshots, try with the -U option

    -U,--update-snapshots                  Forces a check for updated
                                           releases and snapshots on remote
                                           repositories
    

    However, you said:

    I did do a 'mvn clean deploy', so the snapshot version should be somewhere in the maven central repository.

    This is just not possible, your snapshot is going somewhere else. If I do a mvn clean deploy without configuring my personal repository I get:

    Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter

    To enable deployment, there is some configuration to be added to pom.xml, like for instance:

    <distributionManagement>
    
        <!-- Publish versioned releases here -->
        <repository>
            <id>myrepo</id>
            <name>My releases</name>
            <url>http://nexus.mycompany.com/nexus/content/repositories/releases</url>
        </repository>
    
        <!-- Publish snapshots here -->
        <snapshotRepository>
            <id>myrepo</id>
            <name>my snapshots</name>
            <url>http://nexus.mycompany.com/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
    
    </distributionManagement>
    
    <repositories>
        <repository>
            <id>myrepo</id>
            <name>My Public Repository</name>
            <url>http://nexus.mycompany.com/nexus/content/groups/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    
    0 讨论(0)
  • 2021-02-05 08:56

    Maven would try to download the snapshot automatically and indeed it does (as your error indicates). By default, Maven will look for newer snapshot versions once a day, but you can change that interval in your snapshot repository config (e.g. in settings.xml):

    <updatePolicy>interval:5</updatePolicy>
    

    This will make maven check every 5 minutes (if you build that often). Alternatively, you could use the -U or --update-snapshots option, to force the check manually.

    However, it can't find the dependency. Could you post your repo settings and artifact config for the snapshot dependency?

    Is the org.oop:oop:jar:0.9.9-SNAPSHOT artifact in your repository?

    ... so the snapshot version should be somewhere in the maven central repository.

    No it isn't. I tried to look it up, but couldn't find it. Afaik, there's some staging mechanism, so maybe your settings are just wrong. But normally, as the others already said, you'd go and use your own repository manager like Artifactory or Nexus.

    0 讨论(0)
  • 2021-02-05 09:01

    You can either

    • use a parent project which builds all your snapshots, or
    • deploy your snapshots to your maven build server (nexus/archiva/..) using e.g., mvn:deploy
    0 讨论(0)
  • Let's clear up terminology a bit to make sure there is no misunderstanding.

    "Maven Central" (http://search.maven.org/) is a global site where you only find releases. Central doesn't accept snapshots so deploying there should give you an error.

    You probably mean your local/company wide maven proxy/cache. These can also be configured to reject snapshot versions. In case of Nexus, you can also define more complex rules. In my case, I had an issue there which gave no error during mvn deploy but I could see an error in the server's logs.

    Try to follow the data: Enable debug (mvn -X) to see where Maven uploads the data. Then check the server to see whether the artifacts were really uploaded. Check the server's logs for errors.

    Also note that snapshot dependencies are only refreshed once a day; so this won't work:

    PC #1: mvn install -> Error missing dependency PC #2: mvn deploy PC #1: mvn install -> Dependency is still missing because of "update once per day" policy

    Try mvn install -U to force Maven to refresh its cached metadata.

    0 讨论(0)
  • 2021-02-05 09:09

    Just add this to your ~/.m2/settings.xml:

    <profiles>
      <profile>
         <id>allow-snapshots</id>
            <activation><activeByDefault>true</activeByDefault></activation>
         <repositories>
           <repository>
             <id>snapshots-repo</id>
             <url>https://oss.sonatype.org/content/repositories/snapshots</url>
             <releases><enabled>false</enabled></releases>
             <snapshots><enabled>true</enabled></snapshots>
           </repository>
         </repositories>
       </profile>
    </profiles>
    
    0 讨论(0)
提交回复
热议问题