How to provide name of ivy.xml on command line - ant

I have a little sandbox that I use to publish not-invented-here artifacts to our artifact repository. It has a common build.xml file and a common ivysettings.xml.
I would like to be able to pass the name of the ivy.xml file so I can have exactly one, uniquely-named someartifact-ivy.xml file per artifact I intend to publish.
I tried the following:
#/bin/sh
ant publish -Divy.settings.file=ivy-external-ivysettings.xml -Divy.dep.file=someartifact-ivy.xml
Property -Divy.settings.file=ivy-external-ivysettings.xml succeeds in causing ivy to use my ivy-external-ivysettings.xml file.
However, ivy seems to ignore property -Divy.dep.file=someartifact-ivy.xml and goes looking for ivy.xml instead.
The docs suggest to me that my approach should work, as does an upvoted (currently x6) answer to a similar question.

Related

Trying to publish directory tree and auxiliary properties file with apache ivy, with later complex retrieval

I'm still struggling with figuring out how to integrate Apache Ivy into my somewhat complex Ant build.
If it matters, I'm using ATG Dynamo, which contributes most of the mess I'm trying to deal with.
The result of a build of a module is a "build" directory, with several subdirectories. I need to publish the entire contents of the "build" directory, along with a properties file (env/default.properties) that is not produced by the build, but one property in that file is needed when later retrieving this artifact, as it indicates the absolute path (relative to another property setting) where the contents of the "build" directory need to be installed.
The entire build will have several similarly structured modules. I'm pretty sure the target that does the "ivy:publish" can be defined in a "base" build script that all the module build scripts import.
I imagine the "ivy.xml" for each module would have a "publications" element that specifies the two (?) pieces that are being published, being the "build" directory and the "env/default.properties" file. I've never seen an example that publishes a directory, is that possible? If not, then I would guess that I'd have to specify more processing and detail in the "ivy:publish" target, such that I would first zip up the "build" directory and the "env/default.properties" file both into a zip file and publish that as the single artifact. Is this more likely?
It is quite new in Ivy, and it is not released yet, but there is a concept of "packaging" which can handle directories.
See the official documentation: http://ant.apache.org/ivy/history/trunk/concept.html#packaging
With this feature, Ivy can handle by itself the unzipping of a folder. On the publish part, you are on your own, you'll have to make a zip yourself. On the retrieve part, Ivy will unzip the folder in the cache. So you will still have to do some process to copy it at the proper place.
It has not been tested, but probably you can go even further by implementing a custom unpacking algorithm, which will do the unpacking at the proper place. You'll have to implement a class which extends org.apache.ivy.core.pack.ArchivePacking, and declare it in your ivysettings.xml, like this:
<ivysetting>
<classpath file="${ivy.settings.dir}/custom-packing.jar"/>
<typedef name="customPacking" classname="com.acme.ivy.CustomPacking" />
<customPacking />
</ivysettings>
And then in your ivy.xml, declare your artifact as packaged by your custom packaging name:
<ivy-module version="1.0">
...
<publications>
<artifact name="mydistrib" type="distrib" ext=".zip" packaging="my-custom-packaging" />
</publications>
</ivy-module>

In Ivy what does impossible to publish artifacts FileNotFoundException Error Mean?

I'm working within a large build system that uses Ant/Ivy. I try to use a predefined ant task that uses ivy:publish ant task and get this error:
impossible to publish artifacts for com.company.project1.proj1#MySupportJar;working#server1: java.io.FileNotFoundException: /path_to/ivy-repository/com.company.project1.proj1/MySupportJar/5.1.3.part/MySupportJar-5.1.3.jar (No such file or directory)
The directory in the error message exists up to the version number part (5.1.3.part).
I am new to Ivy but think I get the basics of how it works. I can not find much on the exact meaning of this error so if someone could help or point me to an explanation I think I could resolve the issue from there.
Ant target
<target name="publish-shared" depends="ivyInit, resolve"
description="Publish to the shared repository">
<ivy:publish pubrevision="5.1.3"
resolver="shared"
pubdate="${timestamp}"
forcedeliver="true"
update="true"
conf="distro, docs">
<artifacts pattern="dist/[artifact].[ext]"/>
</ivy:publish>
</target>
Ivy file snippet
<publications>
<artifact name="MySupportJar" type="jar" conf="distro" />
<artifact name="MySupportJar-source" type="source" ext="jar" conf="docs" />
</publications>
Thanks.
Thanks for all the suggestions. Turns out to be a simple solution that I was not looking for.
The problem was permissions at /path_to/ivy-repository/com.company.project1. I did not have write permission. The .part file is a temporary file written by Ivy. Ivy could not write the temporary file so when it got to reading the file it failed to find it.
I'm answering this so that it might help someone later.
Thanks.
I'm fairly new to Ant with Ivy too. What I've done is combine a local Maven repository (Artifactory), with Jenkins as a continuous integration server. When we build a jar, I also produce the Maven pom.xml with it. Then, I use the mvn deploy:file command to deploy the desired build to our Maven repository.
The developer manually deploys the jar to our Maven repository via the Promoted Build plugin to Jenkins. The developer selects the build to deploy to Maven, and then pretty much presses a button, and that build will be deployed.
I actually produce two pomswith each build. One ispom.xmland the other ispom-snapshot.xml`. We deploy the snapshot with each build, so other developers can use the latest jar instead of the officially deployed one. I've put the whole thing in github if you're interested.
The only decent Ant/Ivy documentation I've seen is Manning's Ant in Action by Steve Loughram. If it wasn't for that, I probably would have never even tried Ant with Ivy. The online Ant/Ivy documentation at Apache is just plain awful.
I've looked over what you have. I suspect it might be an issue with your ivy-settings.xml file. Somewhere, it's getting the part string as the valid location for publishing the file. Otherwise, I have no idea.
As I said, we use a Maven repository for our site repository, and then use Maven to actually deploy the jars to the repository. I simply found that much easier to do it that way than to figure out how to do this in pure Ivy. Besides, it also means that our Maven projects can also use the jars from our Ant/Ivy projects.

add local jars to ivy build script

I am working on an existing application that uses ivy to manage dependencies, and the source comes with ivy.xml and ivysettings.xml files. I am trying to add my own jar to the build. What would be the easiest way to do this?
I tried adding a dependency to ivy.xml and I am not sure how to configure the repository directories. Maybe there are easy ways to do this? Any quick and dirty way will do.
The filesystem resolver in conjunction with the chain resolver should help you, assuming that you can modify the ivysettings.xml that you just inherited.
You can store your jars locally on your machine under your Local Ivy cache or your Shared Ivy cache. I believe it's $HOME/.ivy2/local and $HOME/.ivy2/shared and its in the same format as the $HOME/.ivy2/cache directory. If you use <ivy:publish/> Ant task to push your local jars to your local repository, they'll be accessible to all of your projects.
However, I recommend biting the bullet and doing things ...what's the technical term? oh yeah... The correct way.
Go ahead and setup a project wide Ivy/Maven repository where you can fetch your local jars the same way you fetch your third party jars. This way, there is no difference between your local jars, and the third party jars you're using. No one has to think where a particular Jar is located or adjust their Ivy configuration to get one jar or another.
Download either Nexus or Artifactory. You can set these repositories up so that all the third-party jars and your local jars are available as if they're all stored in the same server. You can even add in other jar repositories that are not centrally located.
I recommend Loughran's book Ant in Action. It has an excellent chapter on using Ivy. You can also look at my ivy.dir to see how I configure Ivy, so it's easily accessible to all of our projects.

How to rename a file for a specific maven build profile

I've got changes to my web.xml config file that need to stay local-only since Google-App-Engine chokes on them when we try to use them, and they're really only needed for development purposes.
How can I make maven copy my src/main/webapp/WEB-INF/web_local.xml to be web.xml in the target WEB-INF directory?
I looked into maven-assembly-plugin, but that didn't provide a way to give a name to the ouput file (plus it seemed specifically for building .jar files).
You can use webXml property of the maven-war-plugin plugin configuration to point to custom web.xml

Cleanup Antscript

Are there any tools available that allow the cleanup of a ant script?
I especially need to remove unecessary jar files... The Ant script I have to clean has more than 500 entries and has grown uncrontrolled over time.
There's no automated way of cleaning up jar files. You can look at the various include statements in your Java code, but they merely mention classes to include and not the jar themselves. Even if you can determine that a particular class is served by jarA.jar, it could be that jarA.jar is dependent upon jarB.jar.
You can even start removing jar files one at a time to see what breaks your build. That can be somewhat automated, especially if you specify your classpath via fileset instead of each specific jar. However, what if you actually need a jar for runtime, and not for the build?
My suggestion is to use Ant with Ivy. Ivy gives you the same Maven jar dependency capabilities without converting your project to Maven.
Take a look at Ivy and see how it works with Ant. Then, if possible, ask your developers to determine exactly what jars they need and what versions of those jars they need. You will have to help them. You might have to go through the jars in your repository and attempt to figure out what versions of the jars are in your repository.
You don't have to worry about jars that other jars depend upon. Ivy will take care of that for you. What you simply need are the jars that your developers depend upon, and they should know because they're the ones who use the include statements in their programs to specify a particular dependency.
Once you've determined the primary jars (and revisions) you need, you can easily convert your build.xml files to take advantage of Ivy's jar dependency system. Once you've done that, you can remove all the jars from your source repository since Ant with Ivy will download the required ones from the Internet based Maven repository system.

Resources