IVY resolve to latest.release resolves to wrong artifact - ivy

I have an ivy xml file contains dependencies declarations, but uses the rev="latest.release" settings rather than specifying a hard wired revision.
<dependency org="<organisation name>" name="<module>" rev="latest.release"/>
The reason I am using latest.release is that every Sunday our build process runs and generates 'release' artifacts for ALL modules in our project. These artifacts are named WKXX-YYYY so for example, the most recent was WK05-2017
The problem is, when I do a resolve IVY is resolving the artifacts to version WK50-2016 and I do not understand why. The published ivy.xml that resides with the artifact on our central ivy repo seems correct and the info section states the correct status eg release and the publication date is also correct.
eg
WK50-2016
<info organisation="<org name>" module="<module name>" revision="WK50-2016" status="release" publication="20161218140515"/>
WK05-2017
<info organisation="<org name>" module="<module name>" revision="WK05-2017" status="release" publication="20170205140555"/>
As you can see from the above, the publication date is more recent in the WK05-2017 artifact.
I have also included the ivysettings.xml that is also used as part of the IVY configuration.
ivysettings.xml
<ivysettings>
<settings defaultResolver="chained"/>
<resolvers>
<!-- Remote IVY Repo -->
<filesystem name="remote" changingPattern=".*-SNAPSHOT.*" changingMatcher="regexp" checkmodified="true">
<ivy pattern="${ivy.repo.dir}/[organisation]/[module]/[revision]/ivy.xml"/>
<artifact pattern="${ivy.repo.dir}/[organisation]/[module]/[revision]/[artifact].[ext]"/>
</filesystem>
<!-- Local IVY Repo -->
<filesystem name="local" changingPattern=".*-SNAPSHOT.*" changingMatcher="regexp" checkmodified="true">
<ivy pattern="${ivy.local.repo.dir}/[organisation]/[module]/[revision]/ivy.xml"/>
<artifact pattern="${ivy.local.repo.dir}/[organisation]/[module]/[revision]/[artifact].[ext]"/>
</filesystem>
<!-- Use both the local and remote repos -->
<chain name="chained" changingPattern=".*-SNAPSHOT.*" changingMatcher="regexp" checkmodified="true">
<resolver ref="local" />
<resolver ref="remote"/>
</chain>
</resolvers>
<caches defaultCacheDir="${ivy.cache.dir}" ivyPattern="${ivy.cache.ivy.pattern}" artifactPattern="${ivy.cache.artifact.pattern}"/>
</ivysettings>
Just for reference.
changingPattern=".*-SNAPSHOT.*" changingMatcher="regexp" checkmodified="true"
are used as we also use SNAPSHOT integration artefacts that are built and published when commits are made to trunk. I found that without these attributes ivy would use the local SNAPSHOT even if the version on the remote repo was more recent.
Thanks in advance.

Related

Why does Artifactory require an explicit artifact for some Ivy dependencies

I have an Artifactory server that I use to resolve Ivy dependencies. When I want to add a dependency to my ivy.xml, I sometimes have to add an explicit nested <artifact> tag, and I don't understand why.
Example A:
<dependency org="com.google" name="guava" rev="[7,)" conf="compile,runtime" />
Example B
<dependency org="com.twelvemonkeys.common" name="common-image" rev="3.0.1" conf="compile,runtime">
<artifact name="common-image" ext="jar"/>
</dependency>
Looking at the cached dependencies in the Artifactory tree view, there's nothing that indicates that the last example should need extra info to resolve the dependency, but Artifactory suggests it itself, and the resolution doesn't work without out.
I'm using Ivy against a repository with Maven layout. My settings where generated by Artifactory and look something like:
<?xml version="1.0" encoding="UTF-8"?>
<ivy-settings>
<settings defaultResolver="main" />
<resolvers>
<chain name="main">
<ibiblio
name="public"
m2compatible="true"
root="http://example.org/artifactory/remote-repos" />
</chain>
</resolvers>
</ivy-settings>
Why does Artifactory require an explicit artifact for some Ivy dependencies and not for others?
Edit 20151005: Added Ivy settings example
The tool performing the dependency resolution is the Ivy client and not Artifactory.
Based on the dependency deceleration the Ivy resolver decides which artifact to request from the repository (in your case it is Artifactory).
The artifact feature provides more control on a dependency for which you do not control its ivy file.
It enables to specify the artifacts required, if the dependency has no ivy file.
For more information about the artifact feature and when it should be used consult the Ivy documentation.

Ivy resolve failing for some users

Certain developers on my project are unable to successfully execute an ivy resolve. We use an ivy ssh resolver to a remote server/file system. Impacted developers are typically resolving all but 1 or 2 dependencies successfully. The dependencies that fail to be resolved are the larger jars (example: nasa worldwind). Again, most users are able to resolve all dependencies with no problem. The eclipse project, ivy.xml and ivysettings.xml all come from the software repo and are identical between impacted and unimpacted users. If I copy the failed dependency from my ivy2 cache into an impacted users ivy2 cache, the problem goes away. The ivy resolve is initiated through eclipse/ivyDE.
Things I believe are eliminated:
differences in ivy.xml, ivysetings.xml, and eclipse project
existance of dependency on server
file permission issues on remote file system
network connectivity
version differences in eclipse/ivyDE
Question: What could be causing ivy resolves to fail for some users? I am starting to suspect this may be a timeout issue with ivy, given that it happens with larger jars.
Configuration:
Eclispe Kepler
IvyDE 2.2.0
example ivysettings.xml:
<ivysettings>
<settings defaultResolver="test-chain" />
<resolvers>
<chain name="test-chain">
<ssh name="test-cm" host="IPaddress">
<ivy pattern="/cm/lib/[organisation]/[module]/ivys/ivy-[revision].xml"/>
<artifact pattern="/cm/lib/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]"/>
</ssh>
<url name="test-cm-file">
<ivy pattern="file://cm/lib/[organisation]/[module]/ivys/ivy-[revision].xml"/>
<artifact pattern="file://cm/lib/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]"/>
</url>
</chain>
</resolvers>
</ivysettings>
example ivy.xml:
<?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="test"
module="Application"
status="integration">
</info>
<dependencies>
<dependency org="nasa" name="worldwind" rev="1.4.0"/>
</dependencies>
</ivy-module>
Using Eyad Ebrahim's suggestions, I was able to examine the IvyDE console and gain insight into the problem. The issue turned out to be that several developers did not have an ivysettings.xml set in either the eclipse global or project IvyDE properties. IvyDE was attempting to use an internet resolver by default, which resulted in two subsequent issues including no public repo for products like worldwind, and blocking of certain files by my company network infrastructure. After correctly configuring the ivysettings.xml file, the custom file/url resolvers listed above were used and everything worked.
Thanks!

ivy and artifactory resolving failure

Having a small issue with ivy, artifactory and the spring repo. I was attempting to use:
<dependency org="org.springframework.ldap" name="spring-ldap-core" rev="1.3.2.RELEASE" conf="compile->default"/>
<dependency org="org.springframework.ldap" name="spring-ldap" rev="1.3.2.RELEASE" conf="compile->default"/>
with ivy settings:
<resolvers>
<filesystem name="local">
<ivy pattern="${repository.dir}/[module]/ivy.xml" />
<artifact pattern="${repository.dir}/[module]/[artifact].[ext]" />
</filesystem>
<chain name="chain">
<resolver ref="local"/>
<ibiblio name="artifactory-spring" m2compatible="true" root="http://artifactory.xxx.com:8081/artifactory/spring-release"/>
<ibiblio name="artifactory" m2compatible="true" root="http://artifactory.xxx.com:8081/artifactory/repo1"/>
</chain>
</resolvers>
However, I'm getting errors (ant publish -verbose mode)
[ivy:cachepath] CLIENT ERROR: Not Found url=http://artifactory.xxx.com:8081/artifactory/spring-release/spring-ldap/jars/spring-ldap-1.3.2.RELEASE.jar
[ivy:cachepath] artifactory-spring: no ivy file nor artifact found for org.springframework.ldap#spring-ldap;1.3.2.RELEASE
[ivy:cachepath] tried http://artifactory.xxx.com:8081/artifactory/repo1/org/springframework/ldap/spring-ldap/1.3.2.RELEASE/spring-ldap-1.3.2.RELEASE.pom
[ivy:cachepath] CLIENT ERROR: Not Found url=http://artifactory.xxx.com:8081/artifactory/repo1/org/springframework/ldap/spring-ldap/1.3.2.RELEASE/spring-ldap-1.3.2.RELEASE.pom
[ivy:cachepath] tried http://artifactory.xxx.com:8081/artifactory/repo1/org/springframework/ldap/spring-ldap/1.3.2.RELEASE/spring-ldap-1.3.2.RELEASE.jar
[ivy:cachepath] CLIENT ERROR: Not Found url=http://artifactory.xxx.com:8081/artifactory/repo1/org/springframework/ldap/spring-ldap/1.3.2.RELEASE/spring-ldap-1.3.2.RELEASE.jar
indicating that repo1 doesn't have version 1.3.2 and the spring maven repo doesn't have the pom or anything. How do I get ivy (or maybe artifactory?) to deal with the spring maven repo properly? I'm guessing the spring repo is simply not m2compatible, though I've tried flagging the ibiblio setting to false for this.
Thanks!
You have configured your settings file to download from the non-existent "xxx.com" domain.
Good news is that you don't need a settings file at all, by default ivy will download from the Maven Central repository.
Bad news is that there is no 1.3.2.RELEASE version of the spring-ldap artifact:
spring-ldap versons
spring-ldap-code versions
The following ivy file works:
<dependency org="org.springframework.ldap" name="spring-ldap-core" rev="1.3.2.RELEASE" conf="compile->default"/>
<dependency org="org.springframework.ldap" name="spring-ldap" rev="1.3.1.RELEASE" conf="compile->default"/>

How to publish a test source folder using ivy?

In my project I have two separate source folders - /src where the code is and /test for mock and test objects.
On top of the standard jar (from /src) that ivy successfully publishes for my project I would like to publish another artifact through ivy that only includes the objects in the /test folder in order to be able to share these mock objects with other projects.
Can someone please provide an ivy configuration to support this?
1- You need to build a test-jar from the test-folder, lets call it project-test.jar
<javac destdir="build/test" srcdir="test/">
<classpath refid="test.classpath" />
</javac>
<jar destfile="dist/project-test.jar"
basedir="build/test"/>
2- Define an artifact in your ivy.xml
<publications>
<artifact name="project" type="jar" conf="default" ext="jar"/>
<artifact name="project-test" type="jar" conf="test ext="jar"/>
</publications>
3- Publish
<ivy:resolve
revision="${project.version}"
conf="compile,test"
/>
<!-- Alle Artifacts für compile mit dem jars resolver publishen -->
<ivy:publish
revision="${project.version}">
<artifacts pattern="dist/[artifact]-[revision].[type]" />
</ivy:publish>

Issues using ivy

I am new bie to ivy.
I am using packager resolver and that packager resolver resolves the zip file, unzip it, extracts the jar file from it in temp build file, but it stays temporarily and only the jar file which i specified as a module name gets copied to destination rest of all are ignored. Is there a way i can get all the jar files? I use preseverBuildDirectories but is there a better way to do it?
Also is it possible for me to publish an artifact to svn using normal ivy? I got error while i was trying to use ivy 2.1.0 on XP using ant 1.8.0 java.illegalArguementException saying authorization failed. Is there a way i can work through ivy:publish?
Is there a way i can use ivy variable in packager.xml?
Thanks in advance,
Almas
1) Packager resolver
You need to include an ivy file for the repackaged module listing all the artifacts.
Here's my example that downloads the files associated with the Solr distribution
ivysettings.xml
<ivysettings>
<settings defaultResolver="maven2"/>
<caches defaultCacheDir="${user.home}/.ivy2/cache"/>
<resolvers>
<ibiblio name="maven2" m2compatible="true"/>
<packager name="repackage" buildRoot="${user.home}/.ivy2/packager/build" resourceCache="${user.home}/.ivy2/packager/cache" preserveBuildDirectories="false">
<ivy pattern="file:///${ivy.settings.dir}/packager/[organisation]/[module]/ivy-[revision].xml"/>
<artifact pattern="file:///${ivy.settings.dir}/packager/[organisation]/[module]/packager-[revision].xml"/>
</packager>
</resolvers>
<modules>
<module organisation="org.apache.solr" name="solr" resolver="repackage"/>
</modules>
</ivysettings>
Note how the packager resolver specifies a path to both an ivy and packager file.
The ivy file specifies the artifacts that are part of the package in the publications section.
packager/org.apache.solr/solr/ivy-1.4.0.xml
<ivy-module version="2.0">
<info organisation="org.apache.solr" module="solr" revision="1.4.0"/>
<configurations>
<conf name="jars" description="Jars released with SOLR distribution"/>
<conf name="webapps" description="Web applications"/>
</configurations>
<publications>
<!-- jars -->
<artifact name="solr-cell" conf="jars"/>
<artifact name="solr-clustering" conf="jars"/>
<artifact name="solr-core" conf="jars"/>
<artifact name="solr-dataimporthandler" conf="jars"/>
<artifact name="solr-dataimporthandler-extras" conf="jars"/>
<!-- webapps -->
<artifact name="solr" type="war" conf="webapps"/>
</publications>
</ivy-module>
The packager file contains the logic that copies out each artifact listed in the ivy file for the solr module.
packager/org.apache.solr/solr/packager-1.4.0.xml
<packager-module version="1.0">
<property name="name" value="${ivy.packager.module}"/>
<property name="version" value="${ivy.packager.revision}"/>
<resource dest="archive" url="http://ftp.heanet.ie/mirrors/www.apache.org/dist/lucene/solr/1.4.0/apache-solr-1.4.0.tgz" sha1="521d4d7ce536dd16c424a11ae8837b65e6b7bd2d">
<url href="http://www.apache.org/dist/lucene/solr/1.4.0/apache-solr-1.4.0.tgz"/>
</resource>
<build>
<!-- Jar artifacts -->
<move file="archive/apache-${name}-${version}/dist/apache-${name}-cell-${version}.jar" tofile="artifacts/jars/${name}-cell.jar"/>
<move file="archive/apache-${name}-${version}/dist/apache-${name}-clustering-${version}.jar" tofile="artifacts/jars/${name}-clustering.jar"/>
<move file="archive/apache-${name}-${version}/dist/apache-${name}-core-${version}.jar" tofile="artifacts/jars/${name}-core.jar"/>
<move file="archive/apache-${name}-${version}/dist/apache-${name}-dataimporthandler-${version}.jar" tofile="artifacts/jars/${name}-dataimporthandler.jar"/>
<move file="archive/apache-${name}-${version}/dist/apache-${name}-dataimporthandler-extras-${version}.jar" tofile="artifacts/jars/${name}-dataimporthandler-extras.jar"/>
<!-- War artifacts -->
<move file="archive/apache-${name}-${version}/dist/apache-${name}-${version}.war" tofile="artifacts/wars/${name}.war"/>
</build>
</packager-module>
2) Publish to subversion
I've never used it myself but I think you need to configure the subversion resolver and use this to publish your artifacts
3) Using ivy variable in packager file
The packager file listed above uses two ivy variables. Not sure what your question is.
Update: Supporting 3rd party jars
The publications section of the ivy file include the version number in the name of the 3rd party jar:
ivy file
..
<publications>
<artifact name="abc-1.0" conf="jars"/>
<artifact name="pqr-2.0" conf="jars"/>
</publications>
..
packager file
..
<build>
<move file="archive/apache-${name}-${version}/dist/abc-1.0.jar" tofile="artifacts/jars/abc-1.0.jar"/>
<move file="archive/apache-${name}-${version}/dist/pqr-2.0.jar" tofile="artifacts/jars/pqr-2.0.jar"/>
</build>
..