如何通过带有curl的REST API在Nexus 2上上传具有不同分类器和相同pom.xml的jars? [英] How to upload jars with different classifiers and same pom.xml on Nexus 2 from REST API with curl?

查看:112
本文介绍了如何通过带有curl的REST API在Nexus 2上上传具有不同分类器和相同pom.xml的jars?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为此苦苦挣扎了一段时间了.

I've been struggling with this for quite some while.

背景:我们有一些詹金斯(Jenkins)的工作会产生罐子,还有一些其他的工作会将罐子上载到联系.在我们的案例中,我们正在寻找 myJar-1.0.jar myJar-1.0-myClassifier.jar .显然,它们都是使用相同的 pom.xml 文件生成的.

Background: We have some Jenkins jobs that produce jars and other jobs that upload the jars to nexus. In our case we are looking for myJar-1.0.jar and myJar-1.0-myClassifier.jar. Obviously they are both produced with the same pom.xml file.

我要实现的目标是使用 pom.xml 使用curl命令通过REST API将它们都上传到Nexus(我们使用Nexus2)上. pom.xml 文件看起来像这样:

What I am trying to achieve is to upload both of them on Nexus (We use Nexus2) through the REST API with a curl command using the pom.xml. The pom.xml file looks something like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>my.group.id</groupId>
    <artifactId>myJar</artifactId>
    <version>1.0</version>
    <name>My Name</name>
    <packaging>pom</packaging>
    <properties>
          <otherJar.version>1.5</otherJar.version>
          ...
    </properties>
    <dependencies>
          <dependency>
                    <groupId>x.y</groupId>
                    <artifactId>art</artifactId>
                    <version>{$otherJar.version}</version>
          </dependency>
          ...
    </dependencies>
</project>

我要上传的curl命令(没有分类器的jar)是:

The curl command that I'm using to upload (the jar without the classifier) is:

curl -v -F r=releases -F hasPom=true -F e=jar -F file=@pom.xml -F file=@myJar-1.0.jar -u user:pass http://link/to/nexus/service/local/artifact/maven/content

,这按预期工作.该jar随pom.xml文件中提到的groupid,artifactid和版本上传到nexus.

and this works as expected. The jar is uploaded to nexus with the groupid, artifactid and version mentioned in the pom.xml file.

我的问题是-上传此jar之后,如果我们具有相同的 pom.xml ,如何使用 classifier 上传jar?

My question is - after I upload this jar, how can I upload the jar with the classifier provided we have the same pom.xml?

  • 我应该更改 pom.xml 文件吗?如果可以,怎么办?
  • 我应该修改curl命令吗?我尝试添加 -F c = myClassifier ,但这没有用.这导致Nexus产生错误:ID ='releases'的< html>< body< error>存储库不允许更新工件.</error></body</html> (因为已经有一个具有相同groupid,artifactid和版本的工件-我刚刚上传的工件;看来分类器被忽略了)
  • Should I alter the pom.xml file? If so, how?
  • Should I modify the curl command? I tried adding -F c=myClassifier but that didn't work. That resulted in an error produced by Nexus: <html><body><error>Repository with ID='releases' does not allow updating artifacts.</error></body></html> (because there is already an artifact with same groupid, artifactid and version - the one that I just uploaded; it seems that the classifier is ignored)

推荐答案

因此,我尝试了多种解决方案,但无法提出满足我的要求的解决方案(通过REST API上载具有相同pom和不同分类器的多个jar),一个或多个电话.

So I tried multiple solutions and could not come up with one that satisfies my needs (uploads multiple jars with the same pom and different classifiers through the REST API) with one or more calls.

我最终在运行脚本的机器上安装了maven,并使用 maven deploy:deploy-file 如下:

I ended up installing maven on the machine that was running my scripts and using the maven deploy:deploy-file as follows:

maven deploy:deploy-file
    -DpomFile=pom.xml
    -Dfile=myJar-1.0.jar
    -Dpackaging=jar                    // this doesn't have to be specified, it will be taken from the pom file, however in my case the pom was specifying <packaging>pom</packaging> and the jar ended up with .pom extention
    -Dclassifiers=myClassifier         // here you can define multiple classifiers, comma-separated
    -Dtypes=jar                        // same as above
    -Dfiles=myJar-1.0-myClassifier.jar // same as above
    -DrepositoryId=nexus
    -Durl=http://host:port/nexus/content/repositories/releases

您可以在此处找到完整的文档a>.

You can find the full documentation here.

此外,请注意,您必须在Maven的配置文件( maven_home/conf/settings.xml )中定义您的nexus存储库凭据.在该文件中找到节点 servers 并添加与此类似的内容:

Also, please note that you have to define your nexus repository credentials in the maven's configuration file (maven_home/conf/settings.xml). Find the node servers in that file and add something similar to this:

    <server>
      <id>nexus</id>
      <username>yourUserName</username>
      <password>yourPass</password>
    </server>

最后,我想强调一个事实,我认为这是Nexus2 REST API的缺失功能/错误.从上面的代码片段中可以看到,这可以通过使用maven上传jar来实现,也可以从Nexus界面手动实现.但是,我没有通过REST API做到这一点.可能是因为我找不到正确的调用方式,但找不到

In the end I want to stress the fact that I think this is a missing feature/bug of Nexus2's REST API. As you can see from the snippet above, this can be achieved by uploading the jars with maven and this can also be achieved manually from the Nexus interface. However, I did not manage to do it through the REST API. It could be possible because I did not find the right way to call it, but I couldn't find (almost) any documentation either.. a bummer.

此问题的最后注释-由于此问题无法回答我原来的问题(如何通过REST API来实现?),因此我将保留未解决的问题.

Also, final note for this question - I will leave this unsolved since this does not answer my original question (How can this be achieved through the REST API?).

这篇关于如何通过带有curl的REST API在Nexus 2上上传具有不同分类器和相同pom.xml的jars?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆