12

I would like to retrieve ONLY the library jar when I make use of a dependency entry in my ivy.xml for Red5 (or any project for that matter). No matter how I have configured it, I still get "sources" jars for dependencies. I have scoured the docs and google and have yet to find a solution that works using Ivy 2.2.0.

This set of nodes in my ivy.xml seems to work the best for most libraries, but Spring ignores them.

    <exclude ext="txt" />
    <exclude type="src" />
    <exclude artifact="!sources" />

If anyone has any tips that would work, lets hear them!!

Links to the source xml files

http://red5.googlecode.com/svn/java/server/trunk/ivy.xml

http://red5.googlecode.com/svn/java/server/trunk/ivysettings.xml

http://red5.googlecode.com/svn/java/server/trunk/build.xml

Note

Don't say this is a duplicate, their answers do NOT work:

ivy: prevent downloading sources and .txt files

make ivy not to download sources and license files

Update 1

<dependency org="org.springframework" name="org.springframework.core" rev="3.0.5.RELEASE" transitive="false" />

Produces these two files in my lib directory:

org.springframework.core-3.0.5.RELEASE.jar
org.springframework.core-sources-3.0.5.RELEASE.jar

Update 2 For the bounty, I expect your solution to work with Red5 trunk which is available to everyone as open source. The sources jars are just a annoyance for me and well worth the bounty points.

Community
  • 1
  • 1
Paul Gregoire
  • 9,715
  • 11
  • 67
  • 131
  • try my answer from here: http://stackoverflow.com/questions/6364306/how-to-exclude-commons-logging-dependency-of-spring-with-ivy/6367998#6367998 exclude does not seem to work when its directly under a dependency. – oers Aug 12 '11 at 21:57
  • I've tried something similar to that as well before and it didn't work either. Your answer would exclude library B, a dependency of library A and not "sources jar" of library A from library A. – Paul Gregoire Aug 12 '11 at 22:04
  • is the sources.jar tagged as source type in the repository? Or is it just a normal jar-type? – oers Aug 15 '11 at 10:47
  • I'd like to disagree that the answers you've quoted do not work, as they belong to me :-) – Mark O'Connor Aug 18 '11 at 05:03
  • Mark, that's your right but feel free to grab the project and verify my results. – Paul Gregoire Aug 18 '11 at 13:39
  • I've revised my answer below. I'd recommend using the **ibiblio** resolver instead of **url**. It's more powerful and might be the origin of your problems. Hope this helps – Mark O'Connor Aug 18 '11 at 20:51

5 Answers5

10

i'm using this in build.xml to only retrieve the jars

<ivy:retrieve type="jar"/>
natros
  • 710
  • 4
  • 10
  • 3
    Before adding this attribute, ivy was pulling the javadoc and the source jar as well. After this change, it retrieved only the jar files. Thanks! – Karthik Sankar May 14 '13 at 21:13
9

I revised your ivy.xml and ivysettings.xml files.

To suppress source files I used a default configuration mapping to avoid the need to add a "conf" attribute to each dependency.

    <configurations defaultconfmapping="default">
    ..
    ..

Spring now release their software via Maven central so I revised the ivy settings file to use these instead of the old ivy bundle repositories.

Revised ivy.xml

<ivy-module version="2.0" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
    <info organisation="red5" module="server" />

    <configurations defaultconfmapping="default">
        <conf name="default"/>
        <conf name="java6" extends="default" description="Java 6 dependencies"/>
        <conf name="eclipse" description="Special dependencies in Eclipse"/>
        <conf name="utest" extends="eclipse" description="Unit testing dependencies"/>
    </configurations>

    <dependencies>
        <dependency org="javax" name="javaee-api" rev="5.1.2" />

        <!-- Spring --> 
        <dependency org="org.springframework" name="spring-asm" rev="3.0.5.RELEASE"/>
        <dependency org="org.springframework" name="spring-beans" rev="3.0.5.RELEASE" />
        <dependency org="org.springframework" name="spring-context" rev="3.0.5.RELEASE" />
        <dependency org="org.springframework" name="spring-core" rev="3.0.5.RELEASE" />
        <dependency org="org.springframework" name="spring-expression" rev="3.0.5.RELEASE" />
        <dependency org="org.springframework" name="spring-web" rev="3.0.5.RELEASE" />

        <!-- Logging --> 
        <dependency org="org.slf4j" name="com.springsource.slf4j.api" rev="1.6.1" transitive="false" />
        <dependency org="org.slf4j" name="com.springsource.slf4j.bridge" rev="1.6.1" transitive="false" />

        <dependency name="jul-to-slf4j" rev="1.6.1" />
        <dependency name="log4j-over-slf4j" rev="1.6.1" />
        <dependency name="jcl-over-slf4j" rev="1.6.1" />    
        <dependency name="logback-classic" rev="0.9.28" />
        <dependency name="logback-core" rev="0.9.28" />

        <!-- General --> 
        <dependency org="commons" name="commons-beanutils" rev="1.8.2" />
        <dependency org="org.apache.commons" name="com.springsource.org.apache.commons.codec" rev="1.4.0" transitive="false" />
        <dependency org="org.apache.commons" name="com.springsource.org.apache.commons.collections" rev="3.2.1" transitive="false" />

        <dependency org="commons" name="httpcore" rev="4.1.3" />
        <dependency org="commons" name="httpclient" rev="4.1.2" />

        <dependency org="commons" name="commons-lang3" rev="3.0-beta" />
        <dependency org="org.apache.commons" name="com.springsource.org.apache.commons.modeler" rev="2.0.1" transitive="false" />

        <dependency org="commons" name="commons-pool" rev="1.5.6" />
        <dependency name="quartz" rev="1.8.5" />
        <dependency name="ehcache" rev="2.2.0" />

        <!-- XML -->
        <dependency org="org.apache.xerces" name="com.springsource.org.apache.xerces" rev="2.9.1" transitive="false" />
        <dependency name="xmlrpc" rev="2.0.1" />

        <!-- Mina -->   
        <dependency org="mina" name="mina-integration-beans" rev="2.0.4" />
        <dependency org="mina" name="mina-integration-jmx" rev="2.0.4" />
        <dependency org="mina" name="mina-core" rev="2.0.4" />

        <!-- Scripting -->
        <dependency org="org.objectweb.asm" name="com.springsource.org.objectweb.asm" rev="3.2.0" transitive="false" />
        <dependency org="org.objectweb.asm" name="com.springsource.org.objectweb.asm.commons" rev="3.2.0" transitive="false" />
        <dependency org="org.antlr" name="com.springsource.org.antlr" rev="3.1.3" transitive="false" />
        <dependency org="org.codehaus.groovy" name="com.springsource.org.codehaus.groovy" rev="1.7.0" transitive="false" />
        <dependency name="jruby-complete" rev="1.1.6" />
        <dependency name="jython" rev="2.5" /> 
        <dependency org="org.mozilla.javascript" name="com.springsource.org.mozilla.javascript" rev="1.7.0.R2" transitive="false" />
        <dependency org="javax.xml.stream" name="com.springsource.javax.xml.stream" rev="1.0.1" transitive="false" />
        <dependency org="org.springframework" name="spring-context-support" rev="3.0.5.RELEASE" />

        <!-- Crypto -->
        <dependency name="bcprov-jdk16" rev="145" conf="java6->*" /> 

        <!-- MP3 -->
        <dependency name="jaudiotagger" rev="2.0.4-SNAPSHOT" />           

        <!-- Testing support -->
        <!-- until Eclipse updates their junit version, we have to use this -->
        <dependency org="org.junit" name="com.springsource.org.junit" rev="4.8.1" conf="eclipse->*" transitive="false" />
        <dependency name="GroboUtils" rev="5-core" conf="eclipse->*" />
        <dependency org="org.springframework" name="org.springframework.test" rev="3.0.5.RELEASE" conf="eclipse->*" transitive="false" />
        <dependency org="org.springframework" name="org.springframework.transaction" rev="3.0.5.RELEASE" conf="eclipse->*" transitive="false" />
    </dependencies>
</ivy-module>

Revised ivysettings.xml

<ivysettings>
    <settings defaultResolver="chain"/>
    <resolvers>
        <chain name="chain">
            <ibiblio name='central' m2compatible='true'/>
            <ibiblio name='springsource-external' m2compatible='true' root='http://repository.springsource.com/maven/bundles/external'/>
            <url name="googlecode">
                <artifact pattern="http://red5.googlecode.com/svn/repository/[artifact](-[revision]).[ext]" />
                <artifact pattern="http://red5.googlecode.com/svn/repository/[organisation]/[artifact](-[revision]).[ext]" />
            </url>
        </chain>
    </resolvers>
</ivysettings>
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
2

I would advise to not use the "transitive" attribute on the dependency declaration and instead attempt to solve your problem using configurations.

Configurations in ivy are functionally the same as scopes in Maven, but far more flexible.

I normally declare at least the following 3 configurations in my code

    <configurations>
        <conf name="compile" description="Compile time dependencies"/>
        <conf name="runtime" description="Compile time dependencies" extends="compile"/>
        <conf name="test"    description="Compile time dependencies" extends="runtime"/>
    </configurations>

Corresponds to 3 groups of dependencies I'll need for any java project.

The secret is how you map you depdencies to your configurations. If you only want the jar without it's dependencies, then declare it as follows:

<dependency org="org.springframework" name="org.springframework.core" rev="3.0.5.RELEASE" conf="compile->master"/>

The local compile configuration mapped to the master scope of the remote Maven module. The master scope in Maven excludes any transitive dependencies.

If you want the artifact to include it's transitive dependencies then declare the configuration mapping as follows:

<dependency org="org.springframework" name="org.springframework.core" rev="3.0.5.RELEASE" conf="compile->default"/>

Working ivy.xml file

This will download a single jar.

<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
    <info organisation="red5" module="server" />
    <configurations>
        <conf name="default"/>
        <conf name="java6" extends="default" description="Java 6 dependencies"/>
        <conf name="utest" extends="eclipse" description="Unit testing dependencies"/>
        <conf name="eclipse" description="Special dependencies in Eclipse"/>
    </configurations>
    <dependencies>
        <dependency org="org.springframework" name="org.springframework.core" rev="3.0.5.RELEASE" conf="default->master"/>
    </dependencies>
</ivy-module>

Revised settings file

I would also recommend using the ibiblio resolver, which is designed to understand the Maven 1 and Maven 2 repository formats:

<ivysettings>
    <settings defaultResolver="local"/>
    <resolvers>
        <chain name="local">
            <ibiblio name='springsource-releases' m2compatible='true' root='http://repository.springsource.com/maven/bundles/release'/>
             ..
             ..
        </chain>
    </resolvers>
</ivysettings>

Note I'm using the Springsource Maven repository, which is more likely to be up-to-date. I don't know if they maintain the old ivy repositories properly or not anymore.

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • So far not so good - Impossible to resolve dependencies of red5#server;working@MAGNUS unresolved dependency: org.springframework#org.springframework.asm;3.0.5.RELEASE: configuration not found in org.springframework#org.springframework.asm;3.0.5.RELEASE: 'master'. It was required from red5#server;working@MAGNUS java6 – Paul Gregoire Aug 19 '11 at 21:16
  • Using ibiblio broke the build locally and on hudson, switching back to url fixed it. Ivy can be a real PITA a lot of the time. – Paul Gregoire Aug 29 '11 at 14:46
  • What was the error message you got? You do appear to be suffering more than is normal – Mark O'Connor Aug 29 '11 at 16:16
  • I didn't turn on verbose but they appear in the console as unresolved. I'll have to try this again at another time. The configuration stuff definitively doesnt work in our projects case. – Paul Gregoire Aug 29 '11 at 16:19
  • @Mondain I decided to post a second answer with the working example. I think the reason configurations didn't work was because you were using the old Springsource ivy repositories. You are safer to point ivy at the Maven repositories where possible. Springsource now release via Maven central – Mark O'Connor Sep 12 '11 at 00:02
0

You could try something like this. It uses the artifact and matcher, which is valid for exclude-tags. But don't put the exclude inside the dependency (this seems to be buggy, see my comment):

    <dependencies>
      <dependency org="org.springframework" name="org.springframework.core" rev="3.0.5.RELEASE"">
      </dependency>
      <exclude org="org.springframework" name="org.springframework.core" artifact="*sources*" matcher="glob"/>
</dependencies>
oers
  • 18,436
  • 13
  • 66
  • 75
  • I would respectfully disagree. The exclude functionality is designed to suppress transitive dependencies, not the artifacts associated with the Maven modules. If it works great, but I still think the best solution is to use ivy configuration mappings – Mark O'Connor Aug 18 '11 at 05:12
  • yep configurations are better, I just assumed that these would not work because of the details given in the question. – oers Aug 18 '11 at 06:01
0

Within your dependency, simply specify the individual artifacts that you'd like to retrieve by calling them out with an artifact node. Give this a try:

<dependency org="org.springframework" name="org.springframework.core" rev="3.0.5.RELEASE" transitive="false">
    <artifact name="org.springframework.core" ext="jar" />
</dependency>
Sam T.
  • 497
  • 5
  • 11
  • 1
    I'll try it but I'm fairly certain this wont work since the sources artifact is a jar with the extension of "jar" – Paul Gregoire Aug 15 '11 at 15:28
  • The artifact tag is normally used when trying to retrieve the other jars associated with the Maven module, not the main artifact. See the following answer http://stackoverflow.com/questions/6942989/ivy-cant-download-because-pom-file-and-the-jar-file-name-arent-matching-patte – Mark O'Connor Aug 18 '11 at 05:19