如何使用常春藤和nexus发布第三方文物

Jon*_*Jon 4 ant nexus ivy

我忙着用常春藤弄湿我的脚.我在我的本地PC上运行了一个现有的nexus存储库,以及一个现有的ant构建脚本.
两者都很好.

部分构建脚本有一些文件可以从网络共享中检索我们的第三方jar文件(log4j,xmlbeans,junit,pdf等等) - 最好是笨拙的.

我想使用ivy的依赖机制从nexus存储库中检索这些文件并在构建中使用它.每个3rdparty lib都有一个名称和一组任意文件(jar,dll,license.dat,xml等).

由于我们有大量的这些第三方库,每个lib都有多个文件 - 手动上传到nexus不是一个选项 - 我需要一些我可以用来获取一组文件,给它们一个lib名称,一个版本号和将结果上传到nexus.然后我需要能够从常春藤中检索这个.

我设法让上传部分工作,但撤销过程不起作用.使用我们的xmlbeans lib作为起点,我创建了以下ivy.xml文件

<ivy-module version="1.0">  
<info organisation="thirdparty_tools" module="xmlbeans" status="integration">  
<publications>  
  <artifact name="jsr173_api" type="jar" ext="jar"/>  
  <artifact name="saxon-dom" type="jar" ext="jar"/>  
  <artifact name="saxon-xpath" type="jar" ext="jar"/>  
  <artifact name="saxon" type="jar" ext="jar"/>  
  <artifact name="xbean" type="jar" ext="jar"/>  
  <artifact name="xbean_xpath" type="jar" ext="jar"/>  
  <artifact name="xmlpublic" type="jar" ext="jar"/>  
</publications>  
</ivy-module>  
Run Code Online (Sandbox Code Playgroud)

然后将一些蚂蚁脚本发布到nexus:

 <ivy:resolve/>  
    <ivy:publish <ivy:publish resolver="thirdparty" forcedeliver="true" update="true" revision="${version}" overwrite="true">  
      <artifacts pattern="[artifact].[ext]"/>  
    <ivy:publish/>  
Run Code Online (Sandbox Code Playgroud)

这一切都很好.它将所有jar文件发布到预期目录中的nexus.

当我尝试在我的构建中使用它时遇到麻烦.我为我的构建创建了以下ivy.xml文件:

<ivy-module version="1.0">  
    <info organisation="myCompany" module="GLB_Data"/>  
    <dependencies>  
        <dependency org="thirdparty_tools" name="xmlbeans" rev="2.2.0"/>  
    </dependencies>  
</ivy-module> 
Run Code Online (Sandbox Code Playgroud)

然后当我运行我的构建时 - 它找不到任何东西:

::::::::::::::::::::::::::::::::::::::::::::::  
::          UNRESOLVED DEPENDENCIES         ::  
::::::::::::::::::::::::::::::::::::::::::::::  
:: thirdparty_tools#jsr173_api;2.2.0: not found  
:: thirdparty_tools#saxon-dom;2.2.0: not found  
:: thirdparty_tools#saxon-xpath;2.2.0: not found  
:: thirdparty_tools#saxon;2.2.0: not found  
:: thirdparty_tools#xbean;2.2.0: not found  
:: thirdparty_tools#xbean_xpath;2.2.0: not found  
:: thirdparty_tools#xmlpublic;2.2.0: not found  
:::::::::::::::::::::::::::::::::::::::::::::: 
Run Code Online (Sandbox Code Playgroud)

问题似乎与这种模式有关:

WARN: ==== public: tried  
WARN:   http //localhost:8081/nexus/content/groups/public/thirdparty_tools/jsr173_api/2.2.0/jsr173_api-2.2.0.pom  
WARN:   -- artifact thirdparty_tools#jsr173_api;2.2.0!jsr173_api.jar:  
WARN:   http //localhost:8081/nexus/content/groups/public/thirdparty_tools/jsr173_api/2.2.0/jsr173_api-2.2.0.jar  

ivy seems to be looking for the jsr173_api artifact under its own name, rather than under the xmlbeans folder where it was published to:  
[ivy:publish]   published jsr173_api to http //localhost:8081/nexus/content/repositories/thirdparty/thirdparty_tools/xmlbeans/2.2.0/jsr173_api-2.2.0.jar  
Run Code Online (Sandbox Code Playgroud)

(网址混淆以防止意外).

所以我需要以不同的方式发布,或以不同的方式检索.非常感谢您的想法和建议.

Mar*_*nor 14

Nexus主要是一个Maven存储库,这意味着必须适应Maven结构工件的方式.

由于您专注于批量加载Nexus,我建议您查看以下问题的答案:

将工件上传到Nexus,没有Maven

如果你想坚持常春藤读.....

背景

需要一个Maven POM

您的第一个问题是您的Maven模块需要一个POM文件.此文件描述了maven模块,可以从ivy.xml文件的内容轻松生成(请参阅下面的解决方案).

其次,Maven假设正在构建一个主要工件.例如:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.myspotontheweb</groupId>
  <artifactId>donaldduck</artifactId>
  <version>1.0.1</version>
  <packaging>txt</packaging>
</project>
Run Code Online (Sandbox Code Playgroud)

Maven客户端会将此信息转换为以下URL:

http://<host>/<repo>/com/myspotontheweb/donaldduck/1.0.1/donaldduck-1.0.1.txt
Run Code Online (Sandbox Code Playgroud)

这演示了Nexus如何存储任何类型的二进制依赖项.该包装参数默认为"罐子".

maven如何处理额外的模块工件

虽然Maven专注于单个构建工件,但可以通过将其发布到同一目录中来添加其他补充工件(就像您所做的那样).

这些都没有在Maven POM上市.相反,Maven使用特殊的"分类器"属性.以下是可能的依赖声明.

<dependency>
  <groupId>com.myspotontheweb</groupId>
  <artifactId>donaldduck</artifactId>
  <version>1.0.1</version>
  <classifier>metadata</classifier>
  <type>n3</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)

Maven客户端会将其转换为以下URL:

http://<host>/<repo>/com/myspotontheweb/donaldduck/1.0.1/donaldduck-1.0.1-metadata.n3
Run Code Online (Sandbox Code Playgroud)

开源项目通常以这种方式发布其源代码.

常春藤解决方案

那么最后如何使用常春藤将文件发布到Nexus?

首先确定哪个工件是"主"构建工件,并为您的POM文件添加一个额外的条目:

<ivy-module version='2.0' xmlns:e="http://ant.apache.org/ivy/extra">

    <info organisation="com.myspotonontheweb" module="donaldduck" revision="1.0.1"/>

    <publications>
        <artifact name="donaldduck" type="txt"/>
        <artifact name="donaldduck" type="pom"/>
        <artifact name="donaldduck" type="n3" e:classifier="metadata"/>
        <artifact name="donaldduck" type="zip" e:classifier="disto"/>
    </publications>

</ivy-module>
Run Code Online (Sandbox Code Playgroud)

其他文件也可以列出,但每个文件必须具有唯一的分类器属性.....在这里,您将面临将ANT项目转换为Maven的一个经典问题....您发布的每个jar文件可能都需要有一个单独的POM.它们不是真正的"补充"文物......

假装您不需要发布多个模块....使用以下构建目标来发布您的模块:

<target name="prepare" description="Generate POM">
    <!-- Optional: Intermediate file containing resolved version numbers -->
    <ivy:deliver deliverpattern="${build.dir}/ivy.xml" pubrevision="${publish.revision}" status="release"/>

    <!-- Generate the Maven POM -->
    <ivy:makepom ivyfile="${build.dir}/ivy.xml" pomfile="${build.dir}/donaldduck.pom"/>
</target>

<target name="publish" depends="init,prepare" description="Upload to Nexus">
    <ivy:publish resolver="nexus-deploy" pubrevision="${publish.revision}" overwrite="true" publishivy="false" >
        <artifacts pattern="${build.dir}/[artifact](-[classifier]).[ext]"/>
    </ivy:publish>
</target>
Run Code Online (Sandbox Code Playgroud)

Nexus凭证

为了完整起见,这里是包含Nexus存储库位置和凭据的ivysettings.xml文件:

<ivysettings>
    <settings defaultResolver="nexus-central"/>
    <credentials host="somehost" realm="Sonatype Nexus Repository Manager" username="????" passwd="????"/>
    <resolvers>
        <ibiblio name="nexus-central" root="http://somehost/nexus/content/repositories/central/" m2compatible="true"/>
        <ibiblio name="nexus-deploy" root="http://somehost/nexus/content/repositories/repo" m2compatible="true"/>
    </resolvers>
</ivysettings>
Run Code Online (Sandbox Code Playgroud)

更新

下载工件

要检索所有已发布的工件(而不仅仅是主工件),您需要按如下方式列出它们:

<dependency org="com.myspotontheweb" name="donaldduck" rev="1.0.1">
    <artifact name="donaldduck" type="txt"/>
    <artifact name="donaldduck" type="n3" e:classifier="metadata"/>
    <artifact name="donaldduck" type="zip" e:classifier="distro"/>
</dependency>
Run Code Online (Sandbox Code Playgroud)

功能与以下Maven片段相同:

<dependency>
  <groupId>com.myspotontheweb</groupId>
  <artifactId>donaldduck</artifactId>
  <version>1.0.1</version>
  <type>txt</type>
</dependency>

<dependency>
  <groupId>com.myspotontheweb</groupId>
  <artifactId>donaldduck</artifactId>
  <version>1.0.1</version>
  <classifier>metadata</classifier>
  <type>n3</type>
</dependency>

<dependency>
  <groupId>com.myspotontheweb</groupId>
  <artifactId>donaldduck</artifactId>
  <version>1.0.1</version>
  <classifier>distro</classifier>
  <type>zip</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)