ivy - how to download all sources with just adding one line - ivy

I don't want to modify every single line to tell ivy to download ALL sources that it can of all jars. Is there a way to add just one line or property to tell ivy to get all sources that it can for all jars/binaries that it gets so it's easier for our team to step through the code when we need to.
I guess I am looking for something like mavens "mvn dependency:sources" so I can just have a separate ant target or something.

You could set a default configuration mapping in the ivy.xml file, as follows:
<configurations defaultconfmapping="compile->default;sources->sources">
<conf name="compile" description="Compile classpath"/>
<conf name="sources" description="Source jars"/>
</configurations>
This will create two groups of files. The compile classpath dependencies and the source jars.

Related

How to copy runtime libraries without the provided ones in IVY

I thought I wouldn't need to ask this but I am not having any progress.
The solution to this question:
How are maven scopes mapped to ivy configurations by ivy actually addresses question but in its theoretical part.
I have this configuration:
<conf name="compile" description="???" />
<conf name="runtime" description="???" extends="compile" />
<conf name="test" description="???" extends="runtime" />
<conf name="provided" description="???" />
Assume I have this dependency:
<dependency org="org.apache.tomcat" name="servlet-api" rev="6.0.16" transitive="false" />
What I want is: when I invoke the ivy:retrieve to copy the libraries to the .war lib directory before bundling it, I want only to copy all runtime (and compile implicitly) but no servlet-api.
so how to use ivy:retrieve then?
<ivy:retrieve conf="WHAT_TO_PUT_HERE" />
and how to configure the dependency:
<dependency conf="WHAT_IS_THE_CONF_MAPPING" org="org.apache.tomcat" name="servlet-api" rev="6.0.16" transitive="false" />
I'm plateauing here, so please any help would be appreciated.
Knowing that the ivy.xml for servlet-api defines the artifact with
conf="master"
So I think the question is how to 'really' map Provided scope of maven to the provided configuration of IVY.
This is how you map a dependency onto the local "provided" configuration:
<dependency org="org.apache.tomcat" name="servlet-api" rev="6.0.16" conf="provided->master"/>
The configuration mapping works as follows:
provided->master
^ ^
| |
Local Remote
config config
As explained in the answer the special "master" configuration contains only the artifact published by this module itself, with no transitive dependencies:
How are maven scopes mapped to ivy configurations by ivy
This means the "transitive=false" attribute is not required.
Update
How you use the configuration is up to you. The first option is simpler, but I prefer the second approach because my configuration reports match my classpath contents
Option 1
You can create a single classpath as follows:
<ivy:cachepath pathid="compile.path" conf="compile,provided"/>
This can then be used in the javac task as follows:
<javac ... classpathref="compile.path">
..
Option 2
Or I prefer to have a one-2-one mapping between configurations and classpaths:
<ivy:cachepath pathid="compile.path" conf="compile"/>
<ivy:cachepath pathid="provide.path" conf="provided"/>
The problem with the latter approach is that the javac task need to have the classpath usage explicitly stated as follows:
<javac ...
<classpath>
<path refid="compile.path"/>
<path refid="provided.path"/>
</classpath>
I think this explicitly explains how you use this special provided scope, but it's really up to you.

Ivy Publishing multiple jars in Nexus with different version Number

How to publish multiple jar files having different version number in Nexus Sonatype Repository using ivy and ant.
How Can Write ivy.xml file ??
Suppose I have following two jar files
addressing-1.0.jar and
castor-1.3.jar
How Should I provide version number in ivy.xml as there are two different version number here(1.0 and 1.3) to publish these jar files in Nexus Sonatype Repository with appropriate
version numbers.
Thanking You
Looking for reply to this question.
please
All the files published by a build would be associated with the same release revision.
I suspect that what you need to do is upload dependencies? In which case the simplest way is to use the Nexus GUI or the following answer
Upload artifacts to Nexus, without Maven
Explanation
The ivy file describes both the project dependencies and the files generated and published by the project.
So for example the following files lists the two files which ivy will upload into Nexus, a jar and a POM file:
<ivy-module version='2.0'>
<info organisation="com.myspotonontheweb" module="donaldduck"/>
<publications>
<artifact name="donaldduck" type="jar"/>
<artifact name="donaldduck" type="pom"/>
</publications>
<dependencies>
..
..
<dependencies/>
</ivy-module>
The point is... All files published by this module would have the same version number.
And this is specified by the publish task (See pubrevision attribute):
<ivy:publish resolver="nexus" pubrevision="${publish.revision}" overwrite="true" publishivy="false" >
<artifacts pattern="${build.dir}/[artifact].[ext]"/>
</ivy:publish>
Observation
The files in your example are looks like files available from Maven Central. This means they're automatically proxied by your Nexus server, and can be included in your project as dependencies:
<dependencies>
<dependency org="net.sourceforge.addressing" name="addressing" rev="1.1.1"/>
<dependency org="org.codehaus.castor" name="castor" rev="1.2"/>
<dependencies/>

Apache Ivy & Settings File

I'm writing my first Ivy configuration for a new Java project and am trying to hook my ivy-settings.xml file up to my buildscript.
I've followed all the tutorials and have correctly added the xmlns:ivy="antlib:org.apache.ivy.ant" namespace to my build.xml file. So far I've tried running my resolve and cleancache targets, which run ivy:resolve and ivy:cleancache respectively, and all seems to be working (Ant can find Ivy).
However...when I run ivy:resolve, it defaults to go right to the public repo. Since my resolvers are written to look in my SVN root, I have to conclude that Ivy does not see my ivy-settings.xml file and is going to the public repos by default.
I am purposely keeping my ivy-settings.xml file as a separate project in source control because it will be used by all my projects.
So my question:
How do I instruct the Ant buildscipt to look for a checked-out version of ivy-settings.xml somewhere else in my file system, not just sitting there locally in the same directory as build.xml?
Change the settings file name to:
ivysettings.xml
If you want to change this default name and location (same directory as build file) use the "settings" task
Update
This is how I ensure that the settings file is loaded before invoking the ivy resolve of cleancache tasks. Create a target called init that is declared as a dependency
<target name="init">
<ivy:settings file="../../ivysettings.xml"/>
</target>
<target name="resolve" depends="init">
<ivy:resolve/>
</target>
<target name="clean" description="Cleanup build directory">
<delete dir="${build.dir}"/>
</target>
<target name="clean-all" depends="init,clean" description="Clean and purge caches">
<!-- Purge the ivy cache -->
<ivy:cleancache/>
</target>

ivy simple shared repository

I am trying to compile all sub projects of one big project at my company into many jars with managed dependencies, so that not everybody who works at one project only needs to download the latest jars from a shared repository.
ivy seems to be the solution for our problem, because ivy says that it integrates with ant (out build system) very well. But I cant get through the tutorials, they are all somehow more confusing than helpful.
All I want to achieve for the beginning is to have two small Projects. The first one has one class with one method, the second one is just calling this method. The fist project should compile into a jar that is then downloaded by the second project from the shared repository.
Thanks for your help.
A multi-module project is described in the documentation:
http://ant.apache.org/ivy/history/latest-milestone/tutorial/multiproject.html
and the source code is available in subversion:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/example/multi-project/
The simplified summary of how it works:
Wrapper build
Invokes each individual module build in the correct order. If Module A depends on module B, then B will be built first:
<project xmlns:ivy="antlib:org.apache.ivy.ant" name="build-all" default="build">
<!--
==========================================================================
Use the ivy buildlist task to create an ordered list of sub-project builds
==========================================================================
-->
<target name="build-list">
<ivy:buildlist reference="build-path">
<fileset dir="." includes="modules/**/build.xml"/>
</ivy:buildlist>
</target>
<!--
==============================
Invoke targets in sub-projects
==============================
-->
<target name="build" depends="build-list" description="Invoke build target on sub-projects">
<subant target="build" buildpathref="build-path" />
</target>
</project>
For more information see the buildlist documentation.
Module build
Each module will download it's dependencies at the beginning of it's build
<target name="init">
<ivy:settings file="../../ivysettings.xml"/>
<ivy:resolve/>
</target>
At at the end, will publish it's built artifacts:
<target name="publish" depends="build" description="Publish module artifacts to the respository">
<ivy:publish resolver="${publish.resolver}" pubrevision="${publish.revision}" overwrite="true">
<artifacts pattern="${build.dir}/[artifact].[ext]"/>
</ivy:publish>
</target>
Don't forget that for all this to work each module must declare what it depends on and what it publishes
<ivy-module version='2.0'>
<info organisation='com.myorg' module='mymod'/>
<publications>
<artifact name="mymod" type="jar"/>
</publications>
<dependencies>
..
</dependencies>
</ivy-module>

pack stuff other than target/classes with maven jar

I am using maven jar plugin to package the jar file. But it looks like maven jar plugin just only pack the stuff that stay inside target/classes. I am also want to pack all the classes in target/classes and (resource and class) files from many other directories. How can i do that with maven jar?
The resource files stays in another folder of project.
If you can't (or just don't want to) put them under src/main/resources, you can declare additional resource locations using the <resource> element:
<project>
...
<build>
...
<resources>
<resource>
<directory> [your folder here] </directory>
</resource>
</resources>
...
</build>
...
</project>
See Specifying resource directories.
The other classes are generated classes.
The convention with plugins generating sources it to generate them in target/generated-sources/<tool> and a well implemented plugin should add the specified path as a source directory (so that generated code would be compiled). When they don't, the Build Helper Maven Plugin can come to the rescue.
If you are generating classes, why don't you generate them in ${project.build.outputDirectory} (i.e. target/classes by default)? I don't think you can add a 2nd classes directory anyway.
If this doesn't help, please clarify your exact constraints and requirements.
References
Specifying resource directories
MavenPropertiesGuide