Ivy: how do I remove transitive dependencies?
Asked Answered
T

4

21

I'm using Ivy to manage the dependencies on my project.

So far, I've specified a dependency on Hibernate and servlet-api. However, the hibernate jar itself has a lot of dependencies that aren't really needed, such as jaas and jacc.

This becomes a show-stopper because jaas and jaac are Sun libraries and therefore their licenses forbid to place them in the Maven repos, so Ivy can't find them there.

  • How do I make Ivy download Hibernate but not these two ?
  • As a bonus, if I actually needed those and downloaded their Jars from Sun, in which folder in my machine would Ivy look for them ?
Tonnie answered 28/1, 2009 at 12:48 Comment(0)
E
20

How do I make Ivy download Hibernate but not these two?

Ivy does this using what it calls "configurations." Your ivy.xml that represents Hibernate will need to provide different configurations to represent different use-cases for hibernate. (There is obviously some use of hibernate that does require jaas and jacc, but apparently you don't make use of that case.)

Here is the documentation on configurations. If you want to provide the ivy.xml you are using for hibernate, I can provide pointers on building configurations that will remove the specific libraries you want removed.

If I actually needed those and downloaded their Jars from Sun, in which folder in my machine would Ivy look for them?

The "directories" that ivy looks in for ivy files and artifacts are specified by the list of resolvers you are using. The list of resolvers is specified in the ivy settings file (usually named ivysettings.xml.) Typically, these aren't local directories, but remote URLs. There is; however, a local-file resolver type that will work for this.

If you do this, you will need to provide both ivy files and the artifacts (jars), each with file-names that match the resolvers patterns. Details on that are in the documentation.

Here is an example local-file resolver from an ivy settings file:

<filesystem name="myfiles" checkconsistency="false" checksums="" transactional="false">
   <ivy pattern="/data/repo/[organisation]/[module]-[revision].ivy.xml"/>
   <artifact pattern="/data/repo/[organisation]/[module]-[revision].[ext]"/>
</filesystem>

Also note that you will need to point your ivy tasks to the correct resolver. You can do this with the resolver attribute on the ant tasks, or with the defaultResolver attribute on the settings element in the ivy settings file.

Here is the documentation on resolvers.

EDIT: The OP found a less-time intensive workaround for his specific original problem. The "exclude" child-tag of the dependency tag did the job for him:

<dependencies>  
   <dependency org="org.hibernate" name="hibernate-core" rev="3.3.1.GA" conf='..'> 
       <exclude name='jaas' /> 
       <exclude name='jacc' />
   </dependency>
</dependencies>
Eller answered 30/1, 2009 at 21:4 Comment(1)
Nice answer, thanks for your time. I discovered later the exclude tag, which so far solves my problem of excluding some libs: <dependencies> <dependency org="org.hibernate" name="hibernate-core" rev="3.3.1.GA" conf='..'> <exclude name='jaas' /> <exclude name='jacc' />Tonnie
F
26

Another option for not downloading any dependencies is to disable them with the transitive attribute. So if you wanted hibernate-core, but none of its dependencies, you could do this:

<dependencies>  
   <dependency org="org.hibernate" name="hibernate-core"
               rev="3.3.1.GA" conf='..'
               transitive="false" /> 
</dependencies>
Feoff answered 18/4, 2009 at 4:4 Comment(1)
Completly removing transitive seems a bit risky, I prefer the "filter by conf" approach.Birkenhead
E
20

How do I make Ivy download Hibernate but not these two?

Ivy does this using what it calls "configurations." Your ivy.xml that represents Hibernate will need to provide different configurations to represent different use-cases for hibernate. (There is obviously some use of hibernate that does require jaas and jacc, but apparently you don't make use of that case.)

Here is the documentation on configurations. If you want to provide the ivy.xml you are using for hibernate, I can provide pointers on building configurations that will remove the specific libraries you want removed.

If I actually needed those and downloaded their Jars from Sun, in which folder in my machine would Ivy look for them?

The "directories" that ivy looks in for ivy files and artifacts are specified by the list of resolvers you are using. The list of resolvers is specified in the ivy settings file (usually named ivysettings.xml.) Typically, these aren't local directories, but remote URLs. There is; however, a local-file resolver type that will work for this.

If you do this, you will need to provide both ivy files and the artifacts (jars), each with file-names that match the resolvers patterns. Details on that are in the documentation.

Here is an example local-file resolver from an ivy settings file:

<filesystem name="myfiles" checkconsistency="false" checksums="" transactional="false">
   <ivy pattern="/data/repo/[organisation]/[module]-[revision].ivy.xml"/>
   <artifact pattern="/data/repo/[organisation]/[module]-[revision].[ext]"/>
</filesystem>

Also note that you will need to point your ivy tasks to the correct resolver. You can do this with the resolver attribute on the ant tasks, or with the defaultResolver attribute on the settings element in the ivy settings file.

Here is the documentation on resolvers.

EDIT: The OP found a less-time intensive workaround for his specific original problem. The "exclude" child-tag of the dependency tag did the job for him:

<dependencies>  
   <dependency org="org.hibernate" name="hibernate-core" rev="3.3.1.GA" conf='..'> 
       <exclude name='jaas' /> 
       <exclude name='jacc' />
   </dependency>
</dependencies>
Eller answered 30/1, 2009 at 21:4 Comment(1)
Nice answer, thanks for your time. I discovered later the exclude tag, which so far solves my problem of excluding some libs: <dependencies> <dependency org="org.hibernate" name="hibernate-core" rev="3.3.1.GA" conf='..'> <exclude name='jaas' /> <exclude name='jacc' />Tonnie
M
0

Browsing the web and blogs, I found the following ivy-settings to work at grabbing jaas/jacc and hibernate

<ivysettings>

<settings defaultResolver="chained" checkUpToDate="true" />

<resolvers>
    <chain name="chained">
        <url name="com.springsource.repository.bundles.release">
            <ivy pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
            <artifact pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
        </url>

        <url name="com.springsource.repository.bundles.external">
            <ivy pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
            <artifact pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
        </url>

        <ibiblio name="ibiblio" m2compatible="true"/>

        <ibiblio name="jboss" root="http://repository.jboss.org/maven2/" m2compatible="true"/>

        <ibiblio name="java-net-maven1" root="http://download.java.net/maven/1" pattern="${java.net.maven.pattern}" m2compatible="false"/>

        <ibiblio name="java-net-maven2" root="http://download.java.net/maven/2/" m2compatible="true"/>

        <ibiblio name="compass" m2compatible="true" root="http://repo.compass-project.org" />

    </chain>

</resolvers>

The jboss ibibilio resolver is what did the trick at grabbing JAAS/JAAC

My ivy.xml then can then pull it in with

<ivy-module version="2.0">

<info organisation="foo" module="Bar"/>
<dependencies>

    <dependency org="com.h2database" name="h2" rev="1.2+"/>

    <dependency org="org.hibernate" name="hibernate-annotations" rev="3.4.0.GA"/>     

</dependencies>

Mercorr answered 29/11, 2009 at 2:42 Comment(0)
M
0

To answer your second sub-question literally, which nobody has done so far, "in which folder in my machine would Ivy look for JARs?" That depends. Assuming you haven't changed the location in ivysettings.xml or another configuration file: for JAAS, this would be: (user home)/.ivy2/cache/javax.security/jaas/jars. If Ivy already unsuccessfully tried to find JAAS in the Maven Central or other repo's, that directory tree should already exist for the most part, and all you need to do is create the "jars" directory and place jaas-1.0.01.jar in it. Ivy will no longer complain about the missing dependency in its next invocation.

EDIT: Then again, see the discussion below to see considerations to not do it like this.

((user home) is C:/Users/(username) on Windows 7).

Marutani answered 8/2, 2012 at 17:0 Comment(3)
this place is only the cache, and you should not put jars in there directly. It is better to use a FileSystemResolver for this case.Merow
From what I gather, FileSystemResolver is still not a portable solution, since the location of the JAR might differ from machine to machine. I still think simply copying a JAR to a directory is quicker (and no dirtier) than editing your Ivy configuration to point to a directory, and letting Ivy accomplish exactly the same thing that you could have done manually. Or does FileSystemResolver do more than that?Payne
The ivy cache could be deleted at any time by the cleancache task. It is even possible to re-define the cache location. You can use properties in ivysettings, so that the filesystem resolver could point to a relative path (or ${user.home}).Merow

© 2022 - 2024 — McMap. All rights reserved.