从没有pom的nexus复制快照工件

时间:2016-08-22 12:08:13

标签: maven maven-dependency-plugin

我想使用dependecy.copy目标下载快照工件。我不想要POM文件。

mvn -U dependency:copy -Dartifact=mygroupId:myArtifactId:myversion-SNAPSHOT:jar

不幸的是,只有当工件已经在本地maven repo缓存中时,这才有效。如果它不在maven缓存中,我会收到以下错误:

Unable to find artifact.
...
foo-public (https://nexus.foo.org/content/groups/public-foo/, releases=true, snapshots=false)

它说foo-public因为我使用的是settings.xml

<mirror>
  <id>foo</id>
  <mirrorOf>*</mirrorOf>
  <name>My Maven Nexus Repository</name>
  <url>http://nexus.foo.org/content/groups/public-foo/</url>
</mirror>

原因似乎是Maven's Super POM为中央仓库设置了snapshots = false。如果我向工作目录添加一个简约pom.xml我没有错误,因为snapshots = true似乎是任何其他repo的默认值。

<project>
<modelVersion>4.0.0</modelVersion>
    <groupId>dummy</groupId>
    <artifactId>dummy</artifactId>
    <version>1</version>
    <repositories>
        <repository>
            <id>dummy</id>
            <url>dummy</url>
        </repository>
    </repositories>
</project>

我目前的工作是在调​​用mvn命令之前编写虚拟POM。另一种可能的解决方法是将以下内容添加到settings.xmlFound in Sonatype nexus book

<profiles>
  <profile>
    <id>nexus</id>
    <!--Enable snapshots for the built in central repo to direct -->
    <!--all requests to nexus via the mirror -->
    <repositories>
      <repository>
        <id>central</id>
        <url>http://central</url>
        <releases><enabled>true</enabled></releases>
        <snapshots><enabled>true</enabled></snapshots>
      </repository>
    </repositories>
 </profile>
</profiles>
<activeProfiles>
  <!--make the profile active all the time -->
  <activeProfile>nexus</activeProfile>
</activeProfiles>

你是否有一个更优雅的想法,没有这么多准备工作?例如命令行开关?

1 个答案:

答案 0 :(得分:1)

一种解决方案是使用dependency:get目标而不是dependeny:copy目标,请参见Apache Maven Dependency Plugin

  

依赖项:获取Mojo

     

此mojo用于使用其Maven坐标从远程存储库中获取工件及其(可选)依赖项。

 mvn dependency:get -DgroupId=org.apache.maven -DartifactId=maven-core -Dversion=2.2.1 -Dpackaging=jar -Dclassifier=sources -DremoteRepositories=central::default::http://repo1.maven.apache.org/maven2,myrepo::::http://myrepo.com/maven2
 mvn dependency:get -DgroupId=org.apache.maven -DartifactId=maven-core -Dversion=2.2.1 -Dpackaging=jar -Dclassifier=sources -DremoteRepositories=http://repo1.maven.apache.org/maven2 
 mvn dependency:get -Dartifact=org.apache.maven:maven-core:2.2.1:jar:sources -DremoteRepositories=http://repo1.maven.apache.org/maven2 -Ddest=/tmp/myfile.jar

您修改的命令:

mvn dependency:get -U -DgroupId=mygroupId -DartifactId=myArtifactId -Dversion=myversion-SNAPSHOT -Dpackaging=jar -Dtransitive=false -s settings.xml -DremoteRepositories=https://nexus.foo.org/content/groups/public-foo/ -Ddest=target/myArtifactId.jar