How to publish 3rdparty artifacts with ivy and nexus

I make my feet wet with ivy. I have an existing nexus repository running on my local PC and an existing ant build script.
Both work fine.

In terms of build scripts, there are several files for extracting our 3rdparty banner files (log4j, xmlbeans, junit, pdf, etc.) from a shared network resource, which is klunky at best.

I want to use ivy dependency mechanisms to extract these files from the nexus repository and use it in the assembly. Each 3rdparty library has a name and an arbitrary set of files (jar, dll, license.dat, xml, etc.).

Since we have a large number of these 3rdparty libs, and each lib has several files - manual loading in nexus is not an option - I need something that I can use to set the set of files, give them the name lib, version number and upload the result to nexus. then I need to get this from ivy.

I was able to download the download part, but the retreival process is not working. Using our xmlbeans lib as a starting point, I created the following ivy.xml file

<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> 

and then some ant script to publish it to nexus:

  <ivy:resolve/> <ivy:publish <ivy:publish resolver="thirdparty" forcedeliver="true" update="true" revision="${version}" overwrite="true"> <artifacts pattern="[artifact].[ext]"/> <ivy:publish/> 

And all this works great. It publishes all jar files in nexus in the expected directory.

The problem arises when I try to use it in my assembly. I created the following ivy.xml file for my build:

 <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> 

Then, when I start my assembly - it does not find anything:

 :::::::::::::::::::::::::::::::::::::::::::::: :: 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 :::::::::::::::::::::::::::::::::::::::::::::: 

The problem is this:

 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 

(URLs run to prevent accidents).

so I need to post differently or search differently. Ideas and suggestions are greatly appreciated.

+4
source share
1 answer

Nexus is basically a Maven repository, which means you need to adapt to how Maven artifacts are structured.

Since you are focused on bulk loading Nexus, I suggest looking at the answer to the following question:

Upload artifacts to Nexus without Maven

If you want to stick with ivy, read .....

Background

Maven POM required

Your first problem is that your Maven module will need a POM file. This file describes the maven module and can be easily generated from the contents of your ivy.xml file (see Solution below).

Secondly, Maven assumes that there is one main artifact. For instance:

 <project> <modelVersion>4.0.0</modelVersion> <groupId>com.myspotontheweb</groupId> <artifactId>donaldduck</artifactId> <version>1.0.1</version> <packaging>txt</packaging> </project> 

The Maven client will translate this information into the following URL:

 http://<host>/<repo>/com/myspotontheweb/donaldduck/1.0.1/donaldduck-1.0.1.txt 

This demonstrates how Nexus can store any type of binary dependency. The default packaging parameter is jar.

How maven handles additional module artifacts

While Maven focuses on one build artifact, you can add additional additional artifacts by placing them in the same directory (as you did).

These are not those listed in Maven MOM. Instead, Maven uses the special classifier attribute. The following is a possible expression about dependency.

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

The Maven client will translate this to the following URL:

 http://<host>/<repo>/com/myspotontheweb/donaldduck/1.0.1/donaldduck-1.0.1-metadata.n3 

Open source projects typically release source code this way.

Ivy Solution

So finally , how can I publish files to Nexus using ivy?

First of all, decide which artifact is the β€œmain” build artifact and add an extra entry for your POM file:

 <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> 

Other files can also be listed, but each of them must have a unique attribute of the classifier ..... Here you will encounter one of the classic problems associated with the ANT project in Maven .... Each jar file you publish will probably need a separate POM. They are not really "additional" artifacts .....

Pretend you don’t need to publish multiple modules .... Use the following build goals to publish your module:

 <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> 

Nexus Credentials

And for completeness, here is the ivysettings.xml file containing the location and credentials of the Nexus repository:

 <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> 

Update

Artifact Download

To get all published artifacts (and not just the main ones), you need to list them as follows:

 <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> 

Functionally the same as the following Maven snippet:

 <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> 
+14
source

Source: https://habr.com/ru/post/1341237/


All Articles