I am working with Apache Ivy to manage transitive dependencies.
Working with Maven was quite a good experience because if there was any dependency that was not available at a remote directory or available with a different version, then Maven would manage those effectively.
However, Ivy gets stuck with this in my case as I am trying to manage Mule dependencies but it is being difficult for Ivy to manage while Maven manages it well without any problems.
One more important point is that I cannot even exclude any dependency because I don't want to exclude but I want Ivy to be capable enough so that it can manage it all or any other way if any.
Below is a screenshot of the error along with the necessary XML files.
ivy.xml
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info
organisation="MyOrganization"
module="TestForIvySupport"
status="integration">
</info>
<dependencies>
<dependency org="org.mule" name="mule-core" rev="3.6.0"/>
</dependencies>
ivysettings.xml
<settings defaultResolver="chained"/>
<resolvers>
<chain name="chained">
<url name="custom-repo">
<ivy pattern="https://repository.mulesoft.org/nexus/content/groups/public/org/[organisation]/[module]/[revision]/ivy-[revision].xml"/>
<artifact pattern="https://repository.mulesoft.org/nexus/content/groups/public/org/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"/>
</url>
<ibiblio name="ibiblio" m2compatible="true" root="http://mirrors.ibiblio.org/maven2/"/>
<ibiblio name="ibiblio1" m2compatible="true" root="http://repo1.maven.org/maven2/"/>
</chain>
</resolvers>
build.xml
<project name="test ivy" default="test" xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="test" description="Test ivy installation">
<ivy:settings file="ivysettings.xml"/>
<ivy:retrieve sync="false" pattern="myfolder/[artifact]-[revision].[ext]"/>
</target>
Using your example I had a different error:
[ivy:resolve] ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:resolve] :: UNRESOLVED DEPENDENCIES ::
[ivy:resolve] ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:resolve] :: org.mule.mvel#mule-mvel2;2.1.9-MULE-005: not found
[ivy:resolve] :: org.mule.common#mule-common;3.6.0: not found
[ivy:resolve] ::::::::::::::::::::::::::::::::::::::::::::::
I eventually got it working but discovered a broken POM.
Working Example
ivy.xml
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info
organisation="MyOrganization"
module="TestForIvySupport"
status="integration">
</info>
<dependencies>
<!-- Exclude the broken dependency -->
<dependency org="org.mule" name="mule-core" rev="3.6.0" conf="default">
<exclude org="com.github.stephenc.eaio-grabbag" module="grabbag"/>
</dependency>
<!-- Just pull down the jar artifact associated with the module -->
<dependency org="com.github.stephenc.eaio-grabbag" name="grabbag" rev="1.8.1" conf="default">
<artifact name="grabbag" type="jar"/>
</dependency>
</dependencies>
</ivy-module>
Notes:
The POM associated with the grabbag dependency is broken.
Work-around tells ivy to ignore the POM and then we explicitly pull down the jar file as a second dependency declaration.
ivysettings.xml
<ivysettings>
<settings defaultResolver="chained"/>
<resolvers>
<chain name="chained" returnFirst="true">
<ibiblio name="central" m2compatible="true"/>
<ibiblio name="mulesoft" m2compatible="true" root="https://repository.mulesoft.org/nexus/content/groups/public"/>
</chain>
</resolvers>
</ivysettings>
Notes:
Simplified the settings file to use ibiblio resources to talk to just two Maven repositories: Maven Central and the Mulesoft repository
Error analysis
Analysis of first error
I tracked this down to a problem with the parent pom of the "mule-core" module.
http://search.maven.org/#artifactdetails|org.mule|mule|3.6.0|pom
There is an override dependency where the property refers to a version of "mule-mvel2" module that doesn't exist in Maven Central
<properties>
..
<muleMvelVersion>2.1.9-MULE-005</muleMvelVersion>
..
</properties>
<dependency>
<groupId>org.mule.mvel</groupId>
<artifactId>mule-mvel2</artifactId>
<version>${muleMvelVersion}</version>
</dependency>
Managed to fix this by adding the following Mulesoft repository.
https://repository.mulesoft.org/nexus
Analysis of second error
Trouble shooting this further I discovered a second cascaded error:
[ivy:resolve] ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:resolve] :: FAILED DOWNLOADS ::
[ivy:resolve] :: ^ see resolution messages for details ^ ::
[ivy:resolve] ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:resolve] :: com.github.stephenc.eaio-grabbag#grabbag;1.8.1!grabbag.non-maven-jar
[ivy:resolve] ::::::::::::::::::::::::::::::::::::::::::::::
This problem is more serious as it's caused by a misconfigured POM file:
http://search.maven.org/#artifactdetails|com.github.stephenc.eaio-grabbag|grabbag|1.8.1|pom
Where the packaging has been changed from the "jar" default
<packaging>non-maven-jar</packaging>
The ivy work-around for is to exclude this broken transitive dependency and then explicitly pull down the jar artifact as a second dependency in the ivy file.
I have raised a github issue with the the project.
Related
I'm using json-schema-validator and guava in the same project. When I try to update either one I get a conflict for findbugs, so one lib is left out.
The working versions are:
json-schema-validator 2.0.0
guava 13.0.1
Both rely on findbugs 1.3.9
The version I'd like to use:
json-schema-validator 2.2.1
guava 16.0.1
Here json-schema-validator needs findbugs (jsr305) 2.0.1 and guava needs findbugs 1.3.9. Is there any way around this problem? With that I mean that I can use json-schema-validator version 2.2.1 and guava 16.0.1 in my project.
Sample files:
build.xml
<project name="example" default="download"
xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="download" description="resolve dependencies with ivy">
<ivy:resolve />
<ivy:retrieve sync="true" type="jar"/>
</target>
</project>
ivy.xml, working
<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info organisation="example" module="example" status="integration">
</info>
<dependencies>
<dependency org="com.github.fge" name="json-schema-validator" rev="2.0.0" />
<dependency org="com.google.guava" name="guava" rev="13.0.1" />
</dependencies>
</ivy-module>
ivy.xml, not working
<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info organisation="example" module="example" status="integration">
</info>
<dependencies>
<dependency org="com.github.fge" name="json-schema-validator" rev="2.2.1" />
<dependency org="com.google.guava" name="guava" rev="16.0.1" />
</dependencies>
</ivy-module>
eviction notice:
[ivy:resolve] :: evicted modules:
[ivy:resolve] com.google.code.findbugs#jsr305;1.3.9 by [com.google.code.findbugs#jsr305;2.0.1] in [default]
#Julien thanks for the hint, according to the example there I changed the retrieve line to
<ivy:retrieve pattern="lib/[artifact]-[revision].[ext]" sync="true"/>
and it works now.
I handle the build of a Java product with dependencies with ant.
Here is my project.properties file:
project.name=foo
project.version=1.0.0
thirdpart.commons-cli.version=1.2
thirdpart.guava.version=16.0.1
This is loaded using the following in my build.xml ant script:
<property file="project.properties"/>
I would like to loop over all properties starting by "thirdpart." and retrieve each time the name between "thirdpart." & ".version" and the value of the property.
Idea behind is then to retrieve the correct jar file from a shared server. Those informations will help me to build up the correct URL to retrieve them, while allowing me to change my dependencies version easily.
How to proceed with ant ? (Thanks for your help).
Instead of building your own dependency manager I would suggest using Apache ivy.
Several advantages. Instead of building and populating a shared server, you could download from Maven Central. Standard Maven repository managers (nexus, artifactory, archiva) can be used to host repositories inside your firewall.
Examples:
Class not found with Ant, Ivy and JUnit - error in build.xml?
How to avoid copying dependencies with Ivy
Your dependencies
Here's an example ivy.xml file to retrieve your dependencies
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations>
<conf name="compile" description="Required to compile application"/>
</configurations>
<dependencies>
<!-- compile dependencies -->
<dependency org="commons-cli" name="commons-cli" rev="1.2" conf="compile->default"/>
<dependency org="com.google.guava" name="guava" rev="17.0-rc2" conf="compile->default"/>
</dependencies>
</ivy-module>
I want to use the Ivy Eclipse plugin to reolve the spring-oxm dependency.
<dependency org="org.springframework" name="spring-oxm" rev="3.2.2.RELEASE" />
But I got below error:
Some projects fail to be resolved Impossible to resolve dependencies
of my class name unresolved dependency:
org.restlet.jee#org.restlet;2.1.1: not found unresolved dependency:
org.restlet.jee#org.restlet.ext.servlet;2.1.1: not found
I googled, and people say the restlet-2.1.1 no longer exist. And I have no idea how to solve this problem.
Its available in this repo http://maven.restlet.org/org/restlet/jee/org.restlet/2.1.1/
Probably you need to add this repository in your Ivy settings or any repository you are using.
Well, i just now had same problem with my Solr 5.5.0 with changing repository for IVY. But that's all waste of time.
Just download org.restlet.ext.servlet jar file from http://maven.restlet.com/org/restlet/jee/org.restlet.ext.servlet/2.1.1/, create folder repository near ivy-settings.xml, copy downloaded file and change ivy-settings.xml like :
<ivysettings>
<settings defaultResolver="chain-example"/>
<resolvers>
<chain name="chain-example">
<ibiblio name="central" m2compatible="true" />
<filesystem name="libraries">
<artifact pattern="${ivy.settings.dir}/repository/[artifact]-[revision].[ext]" />
</filesystem>
</chain>
</resolvers>
</ivysettings>
Enjoy.
Having a problem with Ivy + Maven Snapshots + rev="latest.revision". Ivy is properly parsing the metadata to discover the latest version of the artifact, but it seems to decline downloading it. I'm stuck with an earlier version of the artifact. Does the text below give anyone any ideas why it's doing it?
[ivy:resolve] listing revisions from maven-metadata: http://my-maven/content/repositories/snapshots/ca/spacek/api-project/maven-metadata.xml
[ivy:resolve] my-snapshots: found md file for ca.spacek#api-project;latest.integration
[ivy:resolve] => http://my-maven/content/repositories/snapshots/ca/spacek/api-project/0.0.3-SNAPSHOT/api-project-0.0.3-20121211.132856-8.pom (0.0.3-SNAPSHOT)
[ivy:resolve] my-snapshots: revision already resolved: ca.spacek#api-project;0.0.3-SNAPSHOT
I looked at this and tried setting the pattern the same, but it didn't seem to help. I'm hoping to avoid workarounds like this.
Downloading snapshots works for me. I've supplied a working example below. Possible to supply more details?
I've seen issues with Maven snapshots in the past but that was because the repository metadata files were not being updated as expected, resulting in the wrong artifact being downloaded.
Another possible issue is a invalid cache. Perhaps you could try and purge it (See the "clean-all" target in the example below).
Example
[ivy:resolve] :: Apache Ivy 2.3.0-rc1 - 20120416000235 :: http://ant.apache.org/ivy/ ::
[ivy:resolve] :: loading settings :: file = /?????/ivysettings.xml
[ivy:resolve] :: resolving dependencies :: myOrg#Demo;????
[ivy:resolve] confs: [default]
[ivy:resolve] found commons-lang#commons-lang;2.7-SNAPSHOT in apache-snapshots
[ivy:resolve] downloading https://repository.apache.org/content/groups/snapshots/commons-lang/commons-lang/2.7-SNAPSHOT/commons-lang-2.7-20120610.132226-5.jar ...
build.xml
<project name="demo" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
<property name="build.dir" location="build"/>
<target name="resolve" description="Use ivy to resolve classpaths">
<ivy:resolve/>
</target>
<target name="clean" description="Cleanup build files">
<delete dir="${build.dir}"/>
</target>
<target name="clean-all" depends="clean" description="Additionally purge ivy cache">
<ivy:cleancache/>
</target>
</project>
ivy.xml
<ivy-module version="2.0">
<info organisation="myOrg" module="Demo"/>
<dependencies>
<dependency org="commons-lang" name="commons-lang" rev="2.7-SNAPSHOT"/>
</dependencies>
</ivy-module>
ivysettings.xml
<ivysettings>
<settings defaultResolver="repos" />
<resolvers>
<chain name="repos">
<ibiblio name="central" m2compatible="true"/>
<ibiblio name="apache-snapshots" m2compatible="true" root="https://repository.apache.org/content/groups/snapshots"/>
</chain>
</resolvers>
</ivysettings>
Here is my ivy.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0">
...
<dependencies>
<dependency org="spring" name="richclient" rev="1.1.0"/>
</dependencies>
</ivy-module>
And ivy-settings.xml:
<property name="ivy.local.default.root" value="/home/---/dev/Java/_libraries/_ivy" override="false"/>
<property name="ivy.local.default.ivy.pattern" value="[organisation]/[module]/[revision]/[type]s/[artifact].[ext]" override="false"/>
<property name="ivy.local.default.artifact.pattern" value="[organisation]/[module]/[revision]/[type]s/[artifact].[ext]" override="false"/>
<resolvers>
<filesystem name="local">
<ivy pattern="${ivy.local.default.root}/${ivy.local.default.ivy.pattern}" />
<artifact pattern="${ivy.local.default.root}/${ivy.local.default.artifact.pattern}" />
</filesystem>
</resolvers>
Ivy try to find
/home/---/dev/Java/_libraries/_ivy/spring/richclient/1.1.0/jars/richclient.jar
And here is the problem. Library has 4 jar files.
How to include all jars in project from one dependency in ivy.xml?
Thx
I'm assuming you've just downloaded the jars locally? It won't work unless you also write an ivy.xml file for the downloaded files, listing the artifacts that are associated with the module (See publications section of the ivy.xml doco)
Why not avoid the hassle of maintaining the your own version of someone else's module by using the maven repository provided by Spring?
Add the following to your ivy-settings.xml file:
<resolvers>
<ibiblio name="spring-rcp" m2compatible="true" root="http://spring-rich-c.sourceforge.net/maven2repository"/>
</resolvers>
While Ivy can work using dependencies on individual JAR files, it works better if you define separate ivy.xml files for the dependencies themselves, which specifies the 4 separate JAR files. This ivy.xml defines what Ivy calls a module.
Your application's ivy.xml then expresses a dependency on that module, rather than on specific JAR files.
The Ivy website has a tutorial on modules, I highly recommend reading it
http://ant.apache.org/ivy/history/latest-milestone/tutorial/conf.html