Split retrieved artifacts in two separate lib directories
Asked Answered
D

1

6

In my web application, there are two separate lib directories:

  • /lib, and
  • /web/webroot/WEB-INF/lib.

The idea behind it is that libraries in the latter one are used by front-end code only, and the first one by both the front-end and the business logic code. There is a class loader in place which lets the business logic code not see the jars in /web/webroot/WEB-INF/lib.

How can I tell ivy that certain dependencies should go to the second directory while all others go to first one?

It's not trival since the the web class loader can see jars in both directories and I don't want jars to be in both directories.

Delanadelancey answered 1/11, 2010 at 16:42 Comment(0)
A
15

Configurations are used to create logical groupings of dependencies:

ivy.xml

<ivy-module version="2.0">
    <info organisation="com.myspotontheweb" module="demo"/>
    <configurations>
        <conf name="frontEnd" description="Jars used by front end"/>
        <conf name="businessLogic" description="Jars used for business logic"/>
    </configurations>
    <dependencies>
        <dependency org="commons-lang"    name="commons-lang"    rev="2.5"   conf="businessLogic->default"/>
        <dependency org="commons-codec"   name="commons-codec"   rev="1.4"   conf="businessLogic->default"/>
        <dependency org="commons-cli"     name="commons-cli"     rev="1.2"   conf="frontEnd->default"/>
        <dependency org="commons-logging" name="commons-logging" rev="1.1.1" conf="frontEnd->default"/>
    </dependencies>
</ivy-module>

The ivy retrieve ant task can use these configurations to populate your directories:

build.xml

<target name="init" description="--> retrieve dependencies with ivy">
    <ivy:retrieve conf="businessLogic" pattern="lib/[artifact].[ext]"/>
    <ivy:retrieve conf="frontEnd" pattern="web/webroot/WEB-INF/lib/[artifact].[ext]"/>
</target>

Example

$ find . -type f
./build.xml
./ivy.xml
./lib/commons-lang.jar
./lib/commons-codec.jar
./web/webroot/WEB-INF/lib/commons-cli.jar
./web/webroot/WEB-INF/lib/commons-logging.jar
Alexandro answered 3/11, 2010 at 22:9 Comment(2)
What is the meaning of businessLogic->default and frontEnd-default in the ivy.xml file?Banville
@MarcusJuniusBrutus See #13582919 and #11417804Kinshasa

© 2022 - 2024 — McMap. All rights reserved.