How to copy runtime libraries without the provided ones in IVY
Asked Answered
P

1

7

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.

Prime answered 30/7, 2012 at 14:46 Comment(0)
F
9

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:

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.

Formfitting answered 30/7, 2012 at 22:53 Comment(5)
Does this mean, that when I build the compile class path I include the compile dependencies along with the provided ones (manually create the class path for both) and when I do the retrieve, I do it with runtime conf so Provided is not part of it, right?Prime
I didn't know that I could use two configurations in conf of cachepath and that's why I already started with the second approach. But to be honest, since we are migrating from our 'old way of doing things'. These javac and junit tasks of ANT are so many that I was hoping to minimize the changes as much as possible. But let's stick to good reports and good practices. Thanks.Prime
+1 for great explanation of configuration mappings (with nice ASCII diagram)Cremator
I believe more strictly speaking, the configuration mapping does not map "local" to "remote" configurations, but a configuration of the current module to a dependency configuration (where the latter does not necessarily need to be remotely).Erudition
@Erudition Configuration mappings in ivy is a powerful feature that is very very hard to initially understand.... "Local" to "remote" just works better in my brain :-) I think it's the arrow notation. Perhaps my thinking is flawed, but it originated from light-bulb moment when I understood how ivy maps "scopes" in Maven.Objectivity

© 2022 - 2024 — McMap. All rights reserved.