so I have an existing ant build and I'd like to resolve its dependencies using Ivy. I have an ivy.xml and ivysettings.xml file which both work with IvyDE in Eclipse and also work when run from the command line against the ivy-2.3.0.jar. (They work as in Ivy reports it has downloaded the dependencies).
The problem I have is that they do not work when running from the any build script when the 'rev' attribute is listed as 'latest.integration'. If I specify a version then the dependency is resolved. To be clear this specific dependency is an internal library that is hosted by Artifactory.
I'm fairly stumped as to what I can change or try to identify the problem. I get the same failure when running an ivy findrevision.
To note Jenkins is running on a mac, but I can use the Ivy jar directly to resolve the dependencies using the same ivy files on that machine, the problem is only related to when resolving through Jenkins.
I realise this isn't likely to be something someone can look at and point directly to the problem, especially given that in seemingly all other situations, even running the snippet from the ant build through eclipse, the resolve works correctly. But if anyone has any suggestions they'd be more than welcome!
Anyway my 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="MyOrg"
module="MyModule"
status="integration">
</info>
<dependencies>
<dependency org="MyOrg" name="DEP" rev="latest.integration">
<artifact name="DEP" type="jar" ext="jar" />
</dependency>
<dependency org="junit" name="junit" rev="4.8.1" />
</dependencies>
</ivy-module>
And my ivysettings.xml (The dependency is named for example DEP-0.1-SNAPSHOT.jar)
<?xml version="1.0" encoding="UTF-8"?>
<ivy-settings>
<settings defaultResolver="snapshot" />
<!--Authentication required for publishing (deployment). 'Artifactory Realm' is the realm used by Artifactory so don't change it.-->
<credentials host="HOST" realm="Artifactory Realm" username="USR" passwd="PASS" />
<resolvers>
<chain name="main">
<!-- <ibiblio name="release" m2compatible="true" root="http://HOST/artifactory/libs-release" /> -->
<chain name="snapshot" changingPattern="0.*" checkmodified="true">
<ibiblio name="public" m2compatible="true" root="http://HOST/artifactory/libs-snapshot" />
</chain>
</chain>
</resolvers>
</ivy-settings>
And finally my build script looks something like
<project name="MyModule Continuous Integration" xmlns:ivy="antlib:org.apache.ivy.ant">
....
<target name = "resolveDependencies" >
<ivy:configure file="/MyModule/ivysettings.xml" />
<ivy:findrevision organisation="MyOrg" module="DEP" revision="latest.integration" property="found.revision" />
<echo message="Found revision: ${found.revision}" />
<ivy:resolve file="/MyModule/ivy.xml" refresh="true" type="jar" />
<ivy:cachepath pathid="ivy.dependencies" />
</target>
....
</project>
And for completion the sort of output I'm getting from the Jenkins build is:
[ivy:findrevision] snapshot: Checking cache for: dependency: MyOrg#DEP;latest.integration {}
[ivy:findrevision] don't use cache for MyOrg#DEP;latest.integration: checkModified=true
[ivy:findrevision] default-cache: no cached resolved revision for MyOrg#DEP;latest.integration
[ivy:findrevision] tried http://HOST/artifactory/libs-snapshot/MyOrg/DEP/[revision]/DEP-[revision].pom
[ivy:findrevision] CLIENT ERROR: Not Found url=http://HOST/artifactory/libs-snapshot/MyOrg/DEP/maven-metadata.xml
[ivy:findrevision] maven-metadata not available: http://HOST/artifactory/libs-snapshot/MyOrg/DEP/maven-metadata.xml
[ivy:findrevision] WARN: problem while listing resources in http://HOST/artifactory/libs-snapshot/MyOrg/DEP/ with public:
[ivy:findrevision] WARN: java.lang.NullPointerException null
[ivy:findrevision] tried http://HOST/artifactory/libs-snapshot/MyOrg/DEP/[revision]/DEP-[revision].jar
[ivy:findrevision] maven-metadata not available: http://HOST/artifactory/libs-snapshot/MyOrg/DEP/maven-metadata.xml
[ivy:findrevision] WARN: problem while listing resources in http://HOST/artifactory/libs-snapshot/MyOrg/DEP/ with public:
[ivy:findrevision] WARN: java.lang.NullPointerException null
[ivy:findrevision] public: no ivy file nor artifact found for MyOrg#DEP;latest.integration
Property "found.revision" has not been set
[echo] Found revision: ${found.revision}
Thanks again for any ideas,
Dan.
For future reference, I have managed to resolve this by swapping to the latest Ivy 2.4 alpha build. Seems it must have been a problem with 2.3.0.
Related
Within a Jenkins groovy script I'm trying to download a dependency using the following:
#Grab(group='myorg', module='SuiteCreator', version='1.16.1', conf='jar', transitive=false)
import myorg.myorgAPI
I have a /home/jenkins/.groovy/grapeConfig.xml file with the following:
<?xml version="1.0" encoding="UTF-8"?>
<ivy-settings>
<settings defaultResolver="downloadGrapes"/>
<resolvers>
<chain name="downloadGrapes">
<sftp user="admin" userPassword="pw" host="ivy.myorg.com" name="myrepository" checkmodified="true">
<ivy pattern="/data/ivy/repo/[organisation]/[module]/[branch]/[revision]/ivy-[revision].xml"/>
<artifact pattern="/data/ivy/repo/[organisation]/[module]/[branch]/[revision]/[artifact]-[revision].[ext]"/>
</sftp>
</chain>
</resolvers>
</ivy-settings>
The ivy-1.16.1.xml of the Module I've trying to grab:
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="1.0">
<info organisation="myorg" module="SuiteCreator" branch="master" revision="1.16.1" status="release" publication="20190417105814"/>
<configurations>
<conf name="jar" description="Distribution jar"/>
</configurations>
<publications>
<artifact name="myorg-suitecreator" type="jar" ext="jar" conf="jar"/>
</publications>
</ivy-module>
So I'm just trying to grab the artifact: myorg-suitecreator-1.16.1.jar.
When I run my groovy script in Jenkins I get the following error:
2019.07.09 18:06:15 org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed:
2019.07.09 18:06:15 General error during conversion: Error grabbing Grapes -- [download failed:
myorg#SuiteCreator#master;1.16.1!SuiteCreator.jar]
2019.07.09 18:06:15
2019.07.09 18:06:15 java.lang.RuntimeException: Error grabbing Grapes -- [download failed: myorg#SuiteCreator#master;1.16.1!SuiteCreator.jar]
2019.07.09 18:06:15 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
From the error it seems Grape is assuming the Ivy Artifact Name is the same as the Module name. The ivy-1.16.1.xml Artifact Name at: /ivy-module/publications/artifact/#name is defined as myorg-suitecreator However Grab appears to be attempt to download: SuiteCreator.jar.
The artifact pattern in grapeConfig.xml is:
<artifact pattern="/data/ivy/repo/[organisation]/[module]/[branch]/[revision]/[artifact]-[revision].[ext]"/>
And so the file I'm trying to grab is actually: /data/ivy/repo/myorg/SuiteCreator/1.16.1/myorg-suitecreator-1.16.1.jar
Does anyone have any suggestions on how to get this to work (or if Grab can download artifacts with different artifact name to the module name from Ivy?).
I gave up trying to use Grab to achieve this. I found another limitation of Grab is that it doesn't allow the specification of the branch of the artifact you wish to retrieve. I realise that not having releases on a master branch or a single release branch may not be best practice, but we do have this requirement in our dev environment.
Instead I simply used an Invoke Ant build step within Jenkins to retrieve my Ivy artifact. We use ANT already in our dev process so this was not difficult.
The ANT build.xml script is located in the same git repository as the Groovy script I wish to run. The retrieve-suite-creator target is simply an ivy-retrieve
<target name="retrieve-suite-creator" depends="clean, install-ivy">
<ivy:retrieve conf="suite-creator" type="jar" pattern="${build.dir}/[artifact].[ext]" log="${ivy.resolve.log}" settingsRef="${ivy.build.settings}"/>
</target>
Using my ivy.xml (again in the same repo as the groovy script):
<ivy-module version="1.0">
<info organisation="myorg" module="MyAutomation" status="integration" branch="${ivy.branch}"/>
<configurations>
<conf name="suite-creator" description="Configuration for Suite Creator"/>
</configurations>
<dependencies>
<dependency org="myorg" name="SuiteCreator" branch="mybranch" rev="1.16.1" conf="suite-creator->suite-creator" changing="true"/>
</dependencies>
</ivy-module>
I had to add the suite-creator ivy configuration to the SuiteCreator module's ivy.xml (in a separate SuiteCreator Git repo). I couldn't use the existing jar configuration as this also downloaded all the transitive dependencies which I didn't need.
<ivy-module version="1.0">
<info organisation="myorg" module="SuiteCreator" status="integration" branch="${ivy.branch}"/>
<configurations>
<!-- Build configurations -->
<conf name="build" description="Classes used in jar compilation"/>
<conf name="jar" description="Distribution jar"/>
<conf name="suite-creator" description="Just the myorg-suitecreator.jar"/>
</configurations>
<publications>
<artifact name="myorg-suitecreator" type="jar" ext="jar" conf="jar,suite-creator"/>
</publications>
<dependencies>
...
</dependencies>
</ivy-module>
Finally in my Jenkins job after the Invoke Ant build step, I then had an Execute Groovy Script build step, where I had to add the downloaded jar to my Class path.
I've read all the tutorials and examples, and still cannot publish a set of custom jars in my local Ivy repository.
Edit: Basically I want the same behavior as maven-install-plugin.
Here's my setup. I have an Ant task which produces the jars in a given folder. The folder name is not fixed but rather passed as a property in file. I want to get all the jars in this folder and install them in my local Ivy repo so that I can use them on a next step.
Here is my Ant from where I call the ivy:publish:
<project name="Install Ivy Dependencies" xmlns:ivy="antlib:org.apache.ivy.ant" basedir="." default="publish">
<loadproperties srcFile="path_to_folder.properties"/>
<property name="file_pattern" value="${path_to_folder}/[artifact].[ext]" />
<property name="pub_revision" value="1.0.0" />
<target name="resolve">
<ivy:configure file="ivysettings.xml" />
<ivy:resolve file="ivy.xml" />
</target>
<target name="retrieve-all" depends="resolve">
<ivy:retrieve pattern="${file_pattern}" conf="*" />
</target>
<target name="publish" depends="retrieve-all">
<ivy:publish resolver="local" organisation="myOrg" update="true" overwrite="true" pubrevision="${pub_revision}">
<artifacts pattern="${file_pattern}"/>
</ivy:publish>
</target>
</project>
Here's my ivysettings.xml:
<ivysettings>
<resolvers>
<filesystem name="local" local="true"/>
</resolvers>
</ivysettings>
And the 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="myOrg" module="myModule" revision="1.0.0"/>
<publications>
<artifact name="my-custom-jar" ext="jar" type="jar"/>
<artifact name="my-custom-jar-source" ext="jar" type="source"/>
</publications>
</ivy-module>
The error that I am getting when I call the ant task is:
impossible to publish artifacts for myOrg#myModule;1.0.0: java.lang.IllegalStateException: impossible to publish myOrg#myModule;1.0.0!my-custom-jar.jar using local: no artifact pattern defined
I've managed to run my scenario and to resolve my issues using this tutorial There were two major issues in my code/integration.
First one is that you cannot tell Ivy to publish the artifacts in its repository without providing a path to it. I did this with the filesystem resolver:
<filesystem name="local" local="true" transactional="local">
<ivy pattern="${ivy.default.ivy.user.dir}/local/[module]/ivy-[revision].xml" />
<artifact pattern="${ivy.default.ivy.user.dir}/local/[module]/[artifact]-[revision].[ext]" />
</filesystem>
The stupid think about it is this should be build in. If you copy it as is, then everything works. If the config is different, or pointing to a different location - nothing works and you are not told why. I read tons of docs about Apache Ivy and it was nowhere mentioned that these patterns should point to the local Ivy repository. I thought these were the paths from where the jars should be taken. I actually complained about this, but the Ivy documentation is very confusing. Also I think the examples there are wrong. Who would like to publish the artifacts in their ivy.settings.dir. In my case this directory was in my repository!
There was a second issue. It is a smaller one and again very hard to see and fix. There's something wrong the revision param and again the documentation is messed up. If you specify one and the same string for the revision and pub revision the artifacts aren't publish without any explanation why. I fixed it by removing the revision from ivy.xml file.
Last, but not least, I didn't manage to run successfully the "thing" as Ant task, but with java -jar $IVY_JAR ... Maybe the issue was because of the versions, but I was too tired to try it with the fix.
P.S.#cantSleepNow thanks for the help.
You need to add artifact pattern to resolver in ivysettings.xml, something like (example from ivy documentation):
<ivysettings>
<resolvers>
<filesystem name="local" local="true">
<ivy pattern="${ivy.settings.dir}/1/[organisation]/[module]/ivys/ivy-[revision].xml"/>
<artifact pattern="${ivy.settings.dir}/1/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]"/>
</filesystem>
</resolvers>
</ivysettings>
I am using Ant to build my project and Ivy to resolve its dependencies. My project has a dependency which publishes snapshots to my internal Artifactory server.
If the dependency has released a new snapshot, and I do an <ivy:retrieve />, Ivy gets the new snapshot but keeps the previous snapshot around. So I have two versions of the dependency in my lib directory.
The dependency snapshots are named like depproject-1.0.0+23.jar where 23 is the build number. It is published at an address like http://artifactory.example.com/example-snapshots-local/com.example/depproject/1.0-SNAPSHOT/depproject-1.0.0+23.jar. This is not a Maven repository, and it is configured to store unique snapshots.
I am new to Ivy. Is this the expected behavior? How can I configure Ivy or Ant so that only the latest dependency snapshot is kept?
ivysettings.xml
<?xml version="1.0" encoding="UTF-8"?>
<ivy-settings>
<settings defaultResolver="main" />
<resolvers>
<chain name="main">
<ibiblio
name="artifactory-example-snapshots"
m2compatible="false"
root="http://artifactory.example.com/example-snapshots-local/"
pattern="[organization]/[module]/1.0-SNAPSHOT/[artifact]-[revision](-[classifier]).[ext]" />
<!-- more repos listed -->
</chain>
</resolvers>
</ivy-settings>
ivy.xml
<ivy-module version="2.0">
<info organisation="com.example" module="myproject" />
<dependencies>
<dependency org="com.example" name="depproject" rev="latest.integration" />
</dependencies>
</ivy-module>
I'm assuming you're using jars in the lib directory to create a classpath, something like:
<path id="compile.path">
<fileset dir="lib" includes="*.jar"/>
</path>
Your issue being multiple jars containing the same classes?
I think you have two options:
Use the ivy cachepath task to manage the build classpaths
Purge the lib directory, using he retrieve task to repopulate with the latest jars
The first option may appear more complicated, but it is actually a very powerful way to use ivy. For an example see:
How to avoid copying dependencies with Ivy
My ivy dependency:
<dependency org="googlecode.com" name="jslint4java" rev="2.0.1" e:suffix="-src">
<artifact name="jslint4java" type="zip"/>
</dependency>
My ivy settings:
<url name="googlecode">
<artifact pattern="http://[module].[organization]/files/[artifact]-[revision][suffix].[ext]"/>
</url>
...
<module organisation="googlecode.com" resolver="googlecode"/>
When I try to resolve the dependencies, I got the following error:
[ivy:retrieve] == resolving dependencies
...#blog;working#...->googlecode.com#jslint4java;2.0.2
[default->*] [ivy:retrieve] tried
http://jslint4java.googlecode.com/files/jslint4java-2.0.2-dist.zip
[ivy:retrieve] CLIENT ERROR: Not Found
url=http://jslint4java.googlecode.com/files/jslint4java-2.0.2-dist.zip
[ivy:retrieve] googlecode: no ivy file nor artifact found for
googlecode.com#jslint4java;2.0.2 [ivy:retrieve] WARN: module not found: googlecode.com#jslint4java;2.0.2 [ivy:retrieve] WARN: ====
googlecode: tried [ivy:retrieve] WARN: -- artifact
googlecode.com#jslint4java;2.0.2!jslint4java.zip: [ivy:retrieve] WARN:
http://jslint4java.googlecode.com/files/jslint4java-2.0.2-dist.zip
I tried to d/l the file by using the url in the last line with wget and the it went well.
But I cannot figure out why ivy failed to d/l the file.
So, I ran the ant task with -d flag to check more info and that's the outcome:
[ivy:resolve] HTTP response status: 404 url=http://jslint4java.googlecode.com/files/jslint4java-2.0.1-src.zip.sha1
[ivy:resolve] CLIENT ERROR: Not Found url=http://jslint4java.googlecode.com/files/jslint4java-2.0.1-src.zip.sha1
[ivy:resolve] HTTP response status: 404 url=http://jslint4java.googlecode.com/files/jslint4java-2.0.1-src.zip.md5
[ivy:resolve] CLIENT ERROR: Not Found url=http://jslint4java.googlecode.com/files/jslint4java-2.0.1-src.zip.md5
Notice that md5 doesn't exist, you have to override the checksums option in the resolver.
<url name="googlecode" checksums="sha1">
I tried the sha1 ONLY, (the default is sha1,md5) and it worked, even though the sha1 failed to download as well.
try to experiment in that area.
I suggest you setup a configuration in your ivy file.
Example
After running the build the following files are present:
|-- build.xml
|-- ivysettings.xml
|-- ivy.xml
`-- lib
`-- jslint4java-2.0.1-src.zip
ivy.xml
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations>
<conf name="source" description="source code distro"/>
</configurations>
<dependencies>
<dependency org="googlecode.com" name="jslint4java" rev="2.0.1" e:suffix="src" conf="source->default">
<artifact name="jslint4java" type="zip"/>
</dependency>
</dependencies>
</ivy-module>
Notes:
Added a "source" configuration. Logical grouping within my ivy project to differentiate from other kinds of dependency.
Note the extra "conf" attribute on the dependency. Mapped to the remote "default" configuration. Unless the remote module has an ivy or POM file default is the safest option.
Revised the extra attribute "suffix". Removed the "-" character. Not a big deal technically, I just think it's best not included in the dependency declaration.
ivysettings.xml
<ivysettings>
<settings defaultResolver="googlecode" />
<resolvers>
<url name="googlecode">
<artifact pattern="http://[module].[organization]/files/[artifact]-[revision]-[suffix].[ext]"/>
</url>
</resolvers>
</ivysettings>
Notes:
Personally I would explicitly state the hostname of the remote repository, here in the settings file (Instead of taking it from the dependency information). This will work though.
build.xml
<project name="demo" default="retrieve" xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="retrieve" description="Use ivy to retrieve artifacts">
<ivy:retrieve pattern="lib/[artifact]-[revision](-[suffix]).[ext]" conf="source"/>
</target>
<target name="clean" description="Cleanup build files">
<delete dir="lib"/>
</target>
<target name="clean-all" depends="clean" description="Additionally purge ivy cache">
<ivy:cleancache/>
</target>
</project>
Notes:
Note how the "suffix" attribute is enclosed within parenthesis. This is an optional extra parameter and may not be part of a dependency.
I have the following ivy file:
<configurations defaultconfmapping="buildtime">
<conf name="buildtime" visibility="private" description="Libraries needed only for compilation" />
<conf name="runtime" description="Libraries only needed at runtime" />
<conf name="test" description="Libraries only needed for testing" />
</configurations>
<dependencies>
<dependency org="net.java.dev" name="jvyaml" rev="0.2.1" conf="runtime" />
<dependency org="org.apache.solr" name="solr-core" rev="3.6.0" conf="runtime" />
</dependencies>
and I have an ant retrieve task that looks like this:
<target name="retrieve-all" depends="resolve">
<ivy:retrieve pattern="lib/[conf]/[artifact]-[revision].[ext]" conf="*" />
</target>
The weird thing is, that all the solr dependencies download into lib/runtime as I'd expect, but the jvyaml module does not! It 'resolves', but will not download into the lib/runtime directory unless I change the dependency declaration to:
<dependency org="net.java.dev" name="jvyaml" rev="0.2.1" conf="runtime->master" />
What is this master configuration and why is it needed to pull the jvyaml jar, but not solr?
Thanks
I would suggest restructuring your configurations as follows:
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations>
<conf name="compile" description="Libraries needed only for compilation" />
<conf name="runtime" description="Libraries only needed at runtime" extends="compile" />
<conf name="test" description="Libraries only needed for testing" extends="runtime" />
</configurations>
<dependencies>
<dependency org="net.java.dev" name="jvyaml" rev="0.2.1" conf="runtime->default" />
<dependency org="org.apache.solr" name="solr-core" rev="3.6.0" conf="runtime->default" />
</dependencies>
</ivy-module>
Important changes introduced:
Use the more standard "compile" configuration
Configuration inheritance using the "extends" attribute. Compile dependencies can then be automatically included in both the runtime and test configurations.
Use configuration mappings, for example: conf="runtime->default". This makes it obvious which local configuration is associated with which remote configuration.
Configuration mappings explained
Configurations are a powerful ivy feature. When ivy downloads Maven modules it performs an internal translation and assigns a standard set of configurations, listed in this answer:
How are maven scopes mapped to ivy configurations by ivy
When declaring a dependency it's a good idea to always make use of a configuration mapping, so that there is no doubt where the dependencies artifacts are assigned.
For example:
<dependency org="??" name="??" rev="??" conf="runtime->default" />
Here we're saying we want the remote module's default dependencies associated with our local runtime configuration.
In practice, there are only two remote configuration mappings you'll actually need:
default: The remote module's artifact and all it's runtime transitive dependencies
master: The remote module's artifact only (No transitive dependencies)
In conclusion, I think your problem was caused by the fact that the remote Maven module's "runtime" scope does not include Maven module's artifact, instead you were getting the non-existant transitive dependencies of the module jvyaml :-(
Some additional advice
I'd also suggest generating an ivy dependency management report, as follows:
<target name="init" description="Resolve dependencies and populate lib dir">
<ivy:resolve/>
<ivy:report todir="${build.dir}/ivy-report" graph="false"/>
<ivy:retrieve pattern="lib/[conf]/[artifact]-[revision].[ext]"/>
</target>
The report will help explain how each dependency ends up on different configurations. Also really useful for determining how transitive dependencies are being managed.
And finally, here's where the configuration inheritance pays off, creating ivy managed ANT classpaths:
<target name="init" description="Resolve dependencies and set classpaths">
<ivy:resolve/>
<ivy:report todir="${build.dir}/ivy-report" graph="false"/>
<ivy:cachepath pathid="compile.path" conf="compile"/>
<ivy:cachepath pathid="runtime.path" conf="runtime"/>
<ivy:cachepath pathid="test.path" conf="test"/>
</target>
Notice that the original solr-core is not retrieved either.
After your resolve, go the cache and check the ivy.xml files for both modules.
You will see that they publish their artifacts in conf=master only
<artifact name="jvyaml" type="jar" ext="jar" conf="master"/>
<artifact name="solr-core" type="jar" ext="jar" conf="master"/>
Which means, you have to do explicit configuration mapping to denote that your builtime configuration should evoke the 'master' configuration of your dependencies. (check configuration mapping).
HOWEVER, the dependencies of the solr-core, have the configuration mapping as you could see in the ivy.xml file:
<dependency org="org.apache.solr" name="solr-solrj" rev="3.6.0" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
I think it's the master(*) thingy.
What I usually do is in my own ivy.xml file when I declare dependencies I do the mapping:
<dependency org="net.java.dev" name="jvyaml" rev="0.2.1" conf="runtime->master" />
This one says the runtime be evoking the master configuration in the designated dependency.
You could do
conf="runtime,test->master"
as well