How to copy runtime libraries without the provided ones in IVY

元气小坏坏 提交于 2019-12-01 03:45:14

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/11723865/how-to-copy-runtime-libraries-without-the-provided-ones-in-ivy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!