right working of ivy with archiva repository - maven

I'm trying to understanding and using ivy with archiva, but i have this strange thing that i can't explain,
Build.xml
...some xml code
<target name="resolveArchiva" description="--> go take the jar">
<ivy:settings file="./archivaIvySetting.xml" >
<credentials host="my host to Archiva" realm="my repository's name"
username="user" passwd="passwd"/>
</ ivy:settings>
<ivy:retrieve />
</target>
some other code....
Ivy.xml
<ivy-module version="2.0">
<info organisation="archiva" module="my-repo"/>
<dependencies>
<dependency org="annogen" name="annogen" rev="0.1.0"/>
<dependency org="commons-lang" name="commons-lang" rev="2.1" />
</dependencies>
</ivy-module>
arvchivaIvySetting.xml
<ivysettings>
<settings defaultResolver="archiva" />
<resolvers>
<ibiblio name="archiva" m2compatible="true" root="repositories/internal/"/>
</resolvers>
</ivysettings>
the problem it's that in my repo there is an artifact for annogen but it's not present the common-lang artifact, despite that, the build says that it find the artifacts for both the dependencies, and that's true because i find both .jar in my lib project. How is it possible? it's clear that my setting doesn't point to the archiva rep but to the maven ones but how can i change it?

Related

"com.springsource" prefix on artifact/module causing conflicts

I have a dependency on my project like this:
<dependency org="org.springframework"
name="org.springframework.web.servlet"
rev="3.1.2.RELEASE" />
And it wants to pull things like this:
org.apache.commons#com.springsource.org.apache.commons.logging;1.1.1
which causes issues with other libraries that use a newer version of commons-logging. So I work around it by excluding it like this:
<exclude org="org.apache.commons"
module="com.springsource.org.apache.commons.logging" />
but having to do that kind of defeats the purpose of the conflict management Ivy has built-in. Is there a better way to handle this, or do I have to track down all the potential conflicts manually?
Disclaimer: I'm pretty new to Ivy and dependency management, so I have no idea if this concept extends into the Maven world as well. If not, I apologize for the false tagging.
I'm assuming you are using the EBR repositories in your ivysettings.xml file.
You get those com.springsource dependencies because all the libraries in EBR are valid OSGi bundles and SpringSource transformed normal jars in bundles by prefixing the bundle names with com.springsource.
Also, I'm assuming your project doesn't make use of an OSGi container and you don't actually need OSGi bundles in your project. To get back to resolving normal jars and not OSGi bundles you need not to use the EBR repositories.
In your ivysettings.xml comment the resolvers that point to EBR repositories, for example:
<!-- <resolvers>
<chain name="chained">
<url name="com.springsource.repository.bundles.release">
<ivy pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
<artifact pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>
<url name="com.springsource.repository.bundles.external">
<ivy pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
<artifact pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>
</chain>
</resolvers> -->
And replace those with the ibiblio resolver:
<settings defaultResolver="central"/>
<resolvers>
<ibiblio name="central" m2compatible="true"/>
</resolvers>
Also, you need to change any dependency that, initially, was taken from EBR repositories to the format the usual Maven central repository has. For example, your dependency on org.springframework.web.servlet needs to be changed in ivy.xml to:
<dependency org="org.springframework"
name="spring-web"
rev="3.1.2.RELEASE" />
With the changes above, Ivy will resolve the dependencies from Maven central, as well.

Get latest google drive api by Ivy

I have add resolver to ivysettings.xml
<ibiblio name="google-api-services" root="http://mavenrepo.google-api-java-client.googlecode.com/hg" m2compatible="true" />
But get a error
module not found: com.google.apis#google-api-services-drive;v2-rev13-1.8.0-beta
It resolves fine for me..... Perhaps there is a problem with your ivysettings file?
The following example configures the google api services repo and Maven Central.
<ivysettings>
<settings defaultResolver="repos" />
<resolvers>
<chain name="repos">
<ibiblio name="central" m2compatible="true"/>
<ibiblio name="google-api-services" m2compatible="true" root="http://mavenrepo.google-api-java-client.googlecode.com/hg"/>
</chain>
</resolvers>
</ivysettings>

Getting several jars from artifactory as a package

I am trying to understand how to manage this situation, suppose I have a 3rd party library (best-lib) that consists of three jars (a.jar, b.jar, c.jar) and I will be uploading those jars to a personal Artifactory server, the (best-lib) has two versions 1.0 and 2.0.
What I would like to have in my ivy.xml file is one single dependency to retrieve all those jars at once for example:
<dependencies>
<dependency org="mycompany" name="best-lib" rev="1.0" />
</dependencies>
And this dependency should add all three jars (a, b, and c) of version 1.0.
The question is:
Is this possible?
How can I upload the three jars to artifactory to achieve this behaviour?
Is it possible to upload those jars all at once?
Artifactory alternative solutions are also acceptable (e.g. Nexus or Archivia).
Note: I am not building best-lib I just have its jars, and best-lib is not a library that can be downloaded from a public maven2 repository.
Thanks.
When publishing the "best-lib" module, use an ivy.xml file that lists the 3 jars published by the module:
<ivy-module version="2.0">
<info organisation="mycompany" module="best-lib"/>
<publications>
<artifact name="a" type="jar"/>
<artifact name="b" type="jar"/>
<artifact name="c" type="jar"/>
</publications>
..
..
When you create a dependency against this module, ivy will understand that there are 3 jars in this module.
For an example of how to publish an ivy module see:
Issues using ivy:publish task
Update
If the 3 jars are already in your repository you could publish a stand-alone ivy modules that references the other 3 as dependencies:
<ivy-module version="2.0">
<info organisation="mycompany" module="best-lib" rev="1.0"/>
<dependences>
<dependency org="mycompany" name="a" rev="1.0" />
<dependency org="mycompany" name="b" rev="1.0" />
<dependency org="mycompany" name="c" rev="1.0" />
</dependencies>
Finally, you may need to tell us what format your Artifactory repository uses.... I have been assuming it's an ivy repo. If it's Maven then the concepts are the same but obviously server-side we'd be talking about pom.xml files, instead of ivy.xml (Ivy supports Maven repositories).

Ivy - Add repository, get from specific repository

I'm pretty new to IVY. I'm trying to do the following:
I wanted to add http://mvnrepository.com to the repository list. I'm not sure if I have to define the correct pattern based on how it is defined under mvnrepository.
Also I want a specific library to be downloaded from there instead of from another repository.
This is my ivysettings file:
<ivysettings>
<properties file="build.properties" />
<settings defaultResolver="local-chain"/>
<resolvers>
<ibiblio name="ibiblio-maven2" m2compatible="true"/>
<ibiblio name="java-net-maven2" root="http://download.java.net/maven/2/" m2compatible="true" />
<ibiblio name="maven" root="http://mvnrepository.com/artifact/" m2compatible="true" />
<filesystem name="project-built" checksums="">
<ivy pattern="${repository.dir}/[module]-ivy.xml" />
<artifact pattern="${repository.dir}/[artifact].[ext]" />
</filesystem>
<chain name="local-chain">
<resolver ref="maven"/>
<resolver ref="ibiblio-maven2"/>
<resolver ref="java-net-maven2"/>
<resolver ref="project-built"/>
</chain>
</resolvers>
And this is my ivy file:
<ivy-module version="1.0">
<info organisation="project" module="com.project.test.framework" />
<dependencies>
<dependency org="commons-collections" name="commons-collections" rev="3.2"/>
<dependency org="commons-configuration" name="commons-configuration" rev="1.6"/>
<dependency org="commons-lang" name="commons-lang" rev="2.6"/>
<dependency org="commons-logging" name="commons-logging" rev="1.1"/>
<dependency org="junit" name="junit" rev="4.8"/>
<dependency org="org.seleniumhq.selenium" name="selenium" rev="2.0rc2"/>
<dependency org="net.sf.json-lib" name="json-lib" rev="2.4" conf="default->compile"/>
<dependency org="com.sun.jersey" name="jersey-core" rev="1.8" conf="default->compile"/>
<dependency org="com.sun.jersey" name="jersey-client" rev="1.8" conf="default->compile"/>
</dependencies>
Basically I want JSON to be downloaded from MAVEN mvnrepository. I thought that when I put maven into the first place it will get it from there and that's that. But it doesn't seem to be using mvnrep at all.
I do think it's configured the wrong way.. But I'm not sure how to do it right.
I did read a lot of posts about it, and I still don't feel that I know the solution.
Thanks for any kind of help!!
To force specific resolver for a module use something like this in your ivysettings.xml:
<ivysettings>
<properties file="build.properties" />
<settings defaultResolver="local-chain"/>
<resolvers>
<ibiblio name="ibiblio-maven2" m2compatible="true"/>
<ibiblio name="java-net-maven2" root="http://download.java.net/maven/2/" m2compatible="true" />
<ibiblio name="maven" root="http://mvnrepository.com/artifact/" m2compatible="true" />
<filesystem name="project-built" checksums="">
<ivy pattern="${repository.dir}/[module]-ivy.xml" />
<artifact pattern="${repository.dir}/[artifact].[ext]" />
</filesystem>
<chain name="local-chain">
<resolver ref="maven"/>
<resolver ref="ibiblio-maven2"/>
<resolver ref="java-net-maven2"/>
<resolver ref="project-built"/>
</chain>
</resolvers>
<modules>
<module organisation="json" resolver="maven"/>
</modules>
</ivysettings>
See the documentation for details.
Perhaps you are missing the returnFirst="true" attribute from your chain.

Ivy via Nexus proxy

does anyone knows how do I specify in Ivy something like mirror/mirrorOf in Maven? I'm working with a local Maven proxy (Nexus) and need the tool to specify which of the parent repositories should Nexus proxy be accessing.
In Maven I do simply:
<mirrors>
<mirror>
<id>central-mirror</id>
<mirrorOf>central</mirrorOf>
<url>http://localhost:8081/content/repositories/central</url>
</mirror>
</mirrors>
but I can't find this kind of option in Ivy.
You need to create a public resolver that does what you want (more details # Ivy docs)
Basically save the following snippet under $USERHOME/.ivy2/ivysettings-public.xml. This should do the trick.
<ivysettings>
<resolvers>
<ibiblio name="public" m2compatible="true" root="http://localhost:8081/content/groups/public"/>
</resolvers>
</ivysettings>
The unmodified standard installation has 'nexus' in the URL!
If you need to deploy artifacts, I think the solution is to do something similar to the shared resolver (see link to docs above), but I haven't tried.
I changed your local URL to resolve to the standard 'content/groups/public' which is better since in the maven settings fragment above you're passing all calls through the mirror, not just the ones to central. Just add any additional repositories to that group in the Nexus UI as they come up and you should be fine.
If your project loads it's own ivysettings which doesn't honor the defaults, then these settings will not get loaded and you're again back at zero :(
I don't think such an option exists directly. You could try implementing a chain, and put your Nexus repository ahead of central in that chain. If I understand how chains work correctly (that's a big if), Ivy will check your repository before central, so as long as your repository has the relevant contents central won't be needed.
See the tutorial for details.
This is how I made it work (The answer from #Heron did not work for me):
Create a file with this content:
<ivysettings>
<settings defaultResolver="default"/>
<property name="m2-pattern" value="${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]" override="false" />
<resolvers>
<chain name="default">
<ibiblio name="public" m2compatible="true" root="http://nexus-server:8081/nexus/content/groups/public"/>
</chain>
</resolvers>
</ivysettings>
Refere to it from the ant build:
<ivy:settings file="/Users/wdb/.ivy2/ivysettings-public.xml" />
Ivy is now able to resolve dependencies from my nexus repository.
I have done the same but with Archiva, what is very similar. You only have to declare in a new chain the following:
<chain name="private">
<url name="archiva" m2compatible="true">
<ivy pattern="http://..../archiva/repository/internal/[organisation]/[module]/[revision]/ivy.xml" />
<artifact pattern="http://..../archiva/repository/internal/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
<artifact pattern="http://..../archiva/repository/internal/[organisation]/[module]/[revision]/[artifact].[ext]" />
</url>
</chain>
Archiva manages Maven 2 repositories (artifacts with Maven meta data)
there isn't usually Ivy meta data (ivy.xml).
And the Maven 2 layout is [organisation]/[module]/[revision]/[artifact]-[revision].[ext].
We have only to provide the following information
<url name="archiva" m2compatible="true">
<artifact pattern="http://..../archiva/repository/internal/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>
</chain>
or
<settings defaultResolver="archiva"/>
<resolvers>
<ibiblio name="archiva" m2compatible="true" root="http://.../archiva/repository/internal/[organization]/[module]/[revision]/[artifact]-[revision].[ext]"/>
</resolvers>

Resources