Search code examples
logbackslf4jivyivyde

Why is logback-classic not downloading slf4j-api in my ivy setup?


I'm trying to add slf4j-api and logback-classic dependencies to a project in Eclipse using the IvyDE plugin, but the jars I need aren't showing up in the Ivy Library classpath entry - I'm only getting logback-classic-1.2.3.jar instead of also getting logback-core-1.2.3.jar and slf4j-api-1.7.25.jar.

My ivy.xml looks like this:

<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="foo" module="bar" status="integration"/>
    <dependencies>
        <dependency org="ch.qos.logback" name="logback-classic" rev="1.2.3" conf="*->default"/>
    </dependencies>
</ivy-module>

Ivy console says that I should be getting them to show up:

[IvyDE] Resolve job starting...
[IvyDE] Processing resolve request ivy.xml[*] in test-ivyde
[IvyDE] 1 module(s) to resolve outside the workspace
[IvyDE] Resolving ivy.xml[*] in test-ivyde
:: resolving dependencies :: foo#bar;working@k
    confs: [default]
    found ch.qos.logback#logback-classic;1.2.3 in public
    found ch.qos.logback#logback-core;1.2.3 in public
    found org.slf4j#slf4j-api;1.7.25 in public
:: resolution report :: resolve 14ms :: artifacts dl 2ms
    ---------------------------------------------------------------------
    |                  |            modules            ||   artifacts   |
    |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
    ---------------------------------------------------------------------
    |      default     |   3   |   0   |   0   |   0   ||   3   |   0   |
    ---------------------------------------------------------------------
[IvyDE] Successuful resolve of ivy.xml[*] in test-ivyde

But my Ivy library looks like this:

ivyde sadness

Adding a separate dependency for slf4j-api doesn't change anything, but I shouldn't have to add it since it's a transitive dependency of logback-classic, right?

What could cause IvyDE to not work as I think it should?


Solution

  • Had the same issue and found the root cause, though I'm not sure why was it set like that in logback-classic's ivy file:

    <artifact name="logback-core" type="test-jar" ext="jar" conf="" m:classifier="tests"/>
    <artifact name="slf4j-api" type="test-jar" ext="jar" conf="" m:classifier="tests"/>
    

    Problematic part is this type="test-jar" where you usually have just "jar" (I also found type="bundle" for com.google.guava#guava).

    You can see the effect of adding this type by comparing these two commands:

    java -jar ivy-2.5.0-rc1.jar -confs default -dependency ch.qos.logback logback-classic 1.2.3 -retrieve "[conf]-[type]-[artifact]-[revision].[ext]" -types jar
    java -jar ivy-2.5.0-rc1.jar -confs default -dependency ch.qos.logback logback-classic 1.2.3 -retrieve "[conf]-[type]-[artifact]-[revision].[ext]" -types jar test-jar
    

    First one get 1 artifact and second one gets all 3 as expected. Also, ivy property ivy.resolve.default.type.filter is used for the same thing.

    Btw, that test-jar comes from official Maven POM file for logback-classic:

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</artifactId>
        <type>test-jar</type>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <type>test-jar</type>
        <version>${slf4j.version}</version>
        <scope>test</scope>
    </dependency>
    

    You can also turn off transitive dependency checking by adding transitive="false" to logback-classic entry and then add logback-core and slf4j-api explicitly to your Ivy file.