have several "generic" modules and one module, which is dependent on them (root). I would like to put some information in the generic modules ixy.xml and later read this information in the build.xml of the root. So the generic module ivy.xml looks like:
<ivy-module version="2.0" xmlns:sqsg="http://www.company.com/sqsg/ivy/extra">
<info organisation="company" module="build-scripts" revision="1.0.2" status="integration" sqsg:svnurl="blabla">
</info>
<publications>
...
</publications>
</ivy-module>
I put and extra attribute "svnurl" to the ivy.xml. The root ivy.xml may look like:
<ivy-module version="2.0">
<info organisation="company" module="root" revision="2.0.5" status="integration">
</info>
<dependencies>
<dependency org="company" name="build-scripts" rev="1.0+" changing="true"/>
</dependencies>
</ivy-module>
I want to read the value of the "svnurl" attribute of all dependencies after I made ivy:resolve of the root module. I tried to look at buildlist and listmodules, but it seems to me they lack the functionality I need. Any idea?
Will the info task help?:
<ivy:info organisation="apache" module="info-all" revision="1.0" />
ivy.artifact.[index].extra.[any extra attribute]: For each extra
attribute of the published artifact, a property is created containing
its name. (Since 2.2)
Related
I have a simple ant build with the following ivy dependencies:
<ivy-module version="2.0">
<info organisation="de.jflex" module="examples.simple"/>
<dependencies>
<dependency org="junit" name="junit" rev="4.12"/>
<dependency org="com.google.guava" name="guava" rev="26.0-jre"/>
<dependency org="com.google.truth" name="truth" rev="0.36"/>
</dependencies>
</ivy-module>
ant build fails with:
circular dependency found: com.google.truth#truth;0.36->com.google.testing.compile#compile-testing;0.12->com.google.truth#truth;0.35
But it's not a hard circular dependency: they depend on different versions. How do I work around this?
You are only getting a warning, which is also a default value of the circularDependencyStrategysetting. If you really want to hide this, you can set that attribute to ignore. But it looks like that even if you change this, dependecy resolution will still fail, due to unresolved com.google.gwt#gwt-user;2.8.0: com.google.gwt#gwt;2.8.0->org.sonatype.oss#oss-parent;4
I am dealing with a project using using ANT to build the source code into a EAR. The project over couple of years has grown to a mammoth size, more than fifty modules, and not surprisingly it takes 2 hours to build the source code.
The obvious decision that I made was to migrate this to a modular build using IVY for dependency management between sub-modules of the EAR, so I build only the modules that have changed and then package a new EAR every time. I am stuck trying to find out a good way of figuring out dependencies between these sub-modules. Note that 3rd party dependencies were easy to crack. I simply move all that is in the lib folder of these sub-modules to IVY. But, the former is where I am stuck.
This is what they do:
Copy source from all modules to a directory
Compile "everything" into a global.jar
Add this global.jar to the classpath
Build every individual module thereafter
Now how do I figure out that for example Module C depends on module A and B and so A and B should go as ivy dependency in the former? One way could be to add one module at a time in eclipse and try building, and then eleminate failures because of missing classes; but there has to be a better way than this, I cannot imagine spending the next one month of life figuring that out :)
First of all you need to create ivy repository. I don't know how to do it. Try to find it on ivy site. After that you need to create build.xml and ivy.xml file.
Example build.xml which builds some product which depends on module1
<project name="ivy.test" xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="resolve">
<!-- this line tells ivy to use ${ivy.settings.file} where are ivy repositories; more info http://ant.apache.org/ivy/history/latest-milestone/settings.html -->
<ivy:configure file="${ivy.settings.file}"/>
<!-- resolve ivy dependencies from ivy.xml and put them in ivy cache dir -->
<ivy:resolve file="${build.dir}/ivy.xml" transitive="false" />
<!-- finally copy resolved dependencies to ${ivy.lib.dir} -->
<ivy:retrieve conf="default" pattern="${ivy.lib.dir}/[artifact].[ext]" />
</target>
</project>
Example ivy.xml used to resolve dependencies (will try to find module1 in one of ivy repository defined in ivysettings file)
<ivy-module version="2.0">
<info organisation="your.organisation" module="modulename">
<ivyauthor name="yourname" />
</info>
<configurations>
<conf name="default" description="default conf" />
</configurations>
<dependencies>
<dependency name="module1" org="your.organisation" rev="latest.release" conf="default->default" />
</dependencies>
</ivy-module>
Example ivy.xml used by module1 project (this project depends on module2 and module3; module1 is also published in repository)
<ivy-module version="2.0">
<info organisation="your.organisation" module="module1"> <!-- module name is used in dependency -->
<ivyauthor name="yourname"/>
</info>
<configurations>
<conf name="default" description="default configuration"/>
</configurations>
<publications>
<artifact name="module" ext="dll" type="dll" conf="default"/>
</publications>
<dependencies>
<dependency name="module2" org="your.organisation" rev="latest.release" conf="default->default" />
<dependency name="module3" org="your.organisation" rev="latest.release" conf="default->default" />
</dependencies>
</ivy-module>
I have a huge dependency which exports a number of dependencies. I wish to restrict my retriev to couple of them. The pattern is [artifact]-[revision].[ext].
How do i specify this in ivy:retrieve task call
Configurations in ivy is the mechanism for controlling groups of dependencies within ivy.
Once these configurations have been setup in your ivy file it becomes simple to retrieve them within your ANT build as follows:
<ivy:retrieve pattern="lib/[artifact].[ext]" conf="my_custom_conf"/>
Perhaps you could supply some more details of what you want to achieve and someone can demonstrate how to setup a configuration for this purpose. (I'd also recommend searching the Stackoverflow ivy tag, for other examples)
Update
If an ivy module publishes more than one artifact it's possible to restrict the dependency in your ivy file as follows:
ivy.xml
<configurations>
..
<conf name="archives" description="Configuration containing only archive files"/>
</configurations>
<dependencies>
..
<dependency org="acme" name="foo" rev="2.0" conf="archives->default">
<artifact name="a1" type="tar"/>
<artifact name="an" type="zip"/>
</dependency>
</dependencies>
Alternatively..
Look into the remote modules's ivy.xml. There may already be a configuration setup for these files, in which case it becomes a lot simpler (because it's been pre-setup)
<dependency org="acme" name="foo" rev="2.0" conf="archives->remotearchives"/>
The "conf" part of the dependency is mapping the remote configuration onto your local one.
I want to use the url resolver to download depends. The depends are JS, or XML files. So, I used:
<url name="urlresolver">
<artifact pattern="http://[organisation]/[module]-[revision].[ext]" />
</url>
And
<ivy:retrieve pattern="${build}/[module]-[revision].[ext]"/>
the file is saved in .jar extension.
It's worth digging around the following ivy docs:
Terminology
Main Concepts
Best Practices
The first problem is that your url resolver is not configured to read ivy files for the remote modules (ignoring the first recommendation, in the ivy best practices, to use an ivy file with each module). Without module meta-data ivy will assume you're attempting to download JAR files.
A second problem is that you don't appear to be using an ivy repository to store your files. The following dependency declaration:
<dependency org="yourorg" name="module1" rev="9.1"/>
would be translated into the following URL, using your current settings:
http://yourorg/module1-9.1.jar
The "org" field is designed to specify the organisational unit publishing the module, not the server hostname.
I suspect that you're not really interested in building a repository of files and just want to persuade ivy to download and cache the files? In that case I'd recommend reading the following answer which is using extra attributes on the dependency artifacts to do something similar:
Resolving XSD's using Ivy
Example
ivy.xml
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
..
..
<dependency org="yourorg" name="yourmodule1" rev="9.1">
<artifact name="file1" e:hostname="www.server1.com" type="xml"/>
<artifact name="file2" e:hostname="www.server1.com" type="xml"/>
</dependency>
<dependency org="yourorg" name="yourmodule2" rev="9.1">
<artifact name="file3" e:hostname="www.server2.com" type="xml"/>
<artifact name="file4" e:hostname="www.server2.com" type="xml"/>
</dependency>
..
Note:
Each dependency declares the type of each artifact, plus the additional "hostname" attribute.
If the remote modules had ivy.xml, the publications section would alternatively store this artifact information.
Extra artifacts demonstrate ivy's power in enabling any sort of custom attribute meta-data.
ivysettings.xml
..
<url name="urlresolver">
<artifact pattern="http://[hostname]/files/[organisation]/[module]-[revision].[ext]" />
</url>
..
Demonstrates how the resolver makes use of both the standard attributes and the custom "hostname".
in ivy:publisher the default deliverivypattern is ${ivy.distrib.dir}/[type]s/[artifact]-[revision](-[classifier]).[ext]
I try to set classifier in my ivy.xml under by adding attribute e:classifier="" to the element.
But the [classifier] does not get set?
When ivy:publish runs in my build.xml file it appears to be empty and thereby not included in the file name pattern.
I think I've figured out your problem.
Just to be clear it is the configured resolver that determines the repository filename and not the publish task. Here's my example, which utilises two extra attributes greeting and author in the artifact and ivy filename patterns:
<ivysettings>
<property name="repo.dir" value="${ivy.basedir}/build/repo"/>
<property name="ivy.checksums" value=""/> <!-- Suppress the generation of checksums -->
<settings defaultResolver="internal"/>
<resolvers>
<filesystem name="internal">
<ivy pattern="${repo.dir}/[module]/[author]-ivy(-[greeting])-[revision].xml" />
<artifact pattern="${repo.dir}/[module]/[author]-[artifact]-[greeting]-[revision].[ext]" />
</filesystem>
</resolvers>
</ivysettings>
The values of the extra attributes are determined by the ivy.xml file:
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
<info organisation="myorg" module="hello" e:author="Mark"/>
<publications>
<artifact name="English" ext="txt" type="doc" e:greeting="hello"/>
<artifact name="Irish" ext="txt" type="doc" e:greeting="dia_dhuit"/>
<artifact name="Spanish" ext="txt" type="doc" e:greeting="Hola"/>
</publications>
</ivy-module>
Sure enough when I published the files the values of the greeting and author tags were present:
$ find build -type f
build/repo/hello/Mark-English-hello-1.0.txt
build/repo/hello/Mark-Irish-dia_dhuit-1.0.txt
build/repo/hello/Mark-Spanish-Hola-1.0.txt
build/repo/hello/Mark-ivy-1.0.xml
I had a problem with
Attribute classifier is not allowed to appear in element 'artifact'
I simply added the "extra" namespace in my declaration and was able to use the classifier.
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"
xmlns:e="http://ant.apache.org/ivy/extra">
<dependency org="orphans" name="vaadin-timeline-cval" rev="2.0">
<artifact name="vaadin-timeline-cval" e:classifier="1.3.1" ext="jar"/>
</dependency>
I believe you want the pattern like so. If the greeting isn't defined it will be left out.
[author]-[artifact](-[greeting])-[revision].[ext]
I faced the same issue and we found a way to get the extra attribute in.
my example in the ivysettings.xml look something like...
<resolvers>
<filesystem name="internal">
<ivy pattern="${repo.dir}/[module]/[author]-ivy(-[greeting])-[revision].xml" />
<artifact pattern="${repo.dir}/[module]/[author]-[artifact]-[greeting]-[revision].[ext]" />
</filesystem>
and in your ivy.xml file i put the following: please note that i wanted the greeting value to be dynamic value everytime i publish something (${someValue})
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
<info organisation="myorg" module="hello" e:author="Mark"/>
<publications>
<artifact name="English" ext="txt" type="doc" e:greeting="${someValue}"/>
</publications>
Here is where the trick come in -> In my build file where i call the ivy:publish function, the following attribute have to be set to true (forcedeliver)
<ivy:publish resolver="#{ivy.resolver}"
pubrevision="#{publish.revision}"
status="#{status}"
forcedeliver="true"
overwrite="#{overwrite}"
update="true" />
That's it