Ivy: how do I remove transitive dependencies?

25,324

Solution 1

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>

Solution 2

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>
Share:
25,324
Leonel
Author by

Leonel

Web developer, using Java on the server side. I also look as a hobbyist at other languages such as Python, Ruby and Lisp.

Updated on July 09, 2022

Comments

  • Leonel
    Leonel almost 2 years

    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 ?
  • Leonel
    Leonel about 15 years
    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' />
  • Jan Galinski
    Jan Galinski about 13 years
    Completly removing transitive seems a bit risky, I prefer the "filter by conf" approach.
  • oers
    oers about 12 years
    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.
  • László van den Hoek
    László van den Hoek about 12 years
    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?
  • oers
    oers about 12 years
    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}).