ivy retrieve leads to “module not found: org.slf4j#slf4j-api;${slf4j.version}”

倾然丶 夕夏残阳落幕 提交于 2019-12-22 10:55:32

问题


My question is, why am I able to pull dependencies from some, but not all, of the public ivy repos?

I am using an ant build.xml script to call the ivy:retrieve command. Here is the relevant line from my ivy.xml file, where I have removed all of the other dependencies for clarity:

<dependencies>
    <dependency org="log4j" name="log4j" rev="1.2.16"/>
</dependencies>

which is being pulled from a public repository given in my ivysettings.xml file

<!-- General public repository !-->
    <ibiblio name="public" m2compatible="true"/>

It manages to pull in some of the dependencies, so I know it's accessing the ibiblio repos correctly. However the build fails with the following error:

[ivy:retrieve] 
[ivy:retrieve] :: problems summary ::
[ivy:retrieve] :::: WARNINGS
[ivy:retrieve]      module not found: org.slf4j#slf4j-api;${slf4j.version}
[ivy:retrieve]  ==== public: tried
[ivy:retrieve]    http://repo1.maven.org/maven2/org/slf4j/slf4j-api/${slf4j.version}/slf4j-api-${slf4j.version}.pom
[ivy:retrieve]    -- artifact org.slf4j#slf4j-api;${slf4j.version}!slf4j-api.jar:
[ivy:retrieve]    http://repo1.maven.org/maven2/org/slf4j/slf4j-api/${slf4j.version}/slf4j-api-${slf4j.version}.jar
[ivy:retrieve]      ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:retrieve]      ::          UNRESOLVED DEPENDENCIES         ::
[ivy:retrieve]      ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:retrieve]      :: org.slf4j#slf4j-api;${slf4j.version}: not found
[ivy:retrieve]      ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:retrieve] 
[ivy:retrieve] :: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS

for some reason it cannot grab the jar dependency for slf4j. Why is this happening? If it helps, I've had a coworker run the same build.xml file using the same version of ant and ivy on their workstation, and the build is successful for them. I can provide more info about our dev environments if necessary.


回答1:


If you take a look closely to console output you will see that in line:

[ivy:retrieve]  ==== public: tried
[ivy:retrieve]    http://repo1.maven.org/maven2/org/slf4j/slf4j-api/${slf4j.version}/slf4j-api-${slf4j.version}.pom
[ivy:retrieve]    -- artifact org.slf4j#slf4j-api;${slf4j.version}!slf4j-api.jar:
[ivy:retrieve]    http://repo1.maven.org/maven2/org/slf4j/slf4j-api/${slf4j.version}/slf4j-api-${slf4j.version}.jar
[ivy:retrieve]      ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:retrieve]      ::          UNRESOLVED DEPENDENCIES         ::
[ivy:retrieve]      ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:retrieve]      :: org.slf4j#slf4j-api;${slf4j.version}: not found
[ivy:retrieve]      ::::::::::::::::::::::::::::::::::::::::::::::

you trying to resolve resource located at:

[ivy:retrieve]    http://repo1.maven.org/maven2/org/slf4j/slf4j-api/${slf4j.version}/slf4j-api-${slf4j.version}.pom

and ${slf4j.version} - is a variable that was not instantiated for some reason. May be missed build.properties/ivy.properties, or this variable should be defined directly in build.xml/ivy.settings/ivysettings.xml/whatever_file_define_resolve_variables.xml. But since it was not defined ivy trying to get resource located at exactly

http://repo1.maven.org/maven2/org/slf4j/slf4j-api/${slf4j.version}/slf4j-api-${slf4j.version}.pom

instead of something like

http://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.9/slf4j-api-1.7.9.pom

So to get resolve running you should define variable called 'slf4j.version' some way. Try to search how to define variables for ivy or for ant. There is different ways to do that.




回答2:


Cannot reproduce your problem.

Example

├── build.xml
├── ivysettings.xml
├── ivy.xml
└── lib
    ├── activation-1.1.jar
    ├── geronimo-jms_1.1_spec-1.0.jar
    ├── log4j-1.2.16.jar
    ├── log4j-1.2.16-javadoc.jar
    ├── log4j-1.2.16-sources.jar
    └── mail-1.4.1.jar

build.xml

<project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">

    <target name="build">
        <ivy:retrieve pattern="lib/[artifact]-[revision](-[classifier]).[ext]"/>
    </target>

    <target name="clean">
        <delete dir="lib"/>
        <ivy:cleancache/>
    </target>

</project>

ivy.xml

<ivy-module version="2.0">
    <info organisation="com.myspotontheweb" module="demo"/>

    <dependencies>
        <dependency org="log4j" name="log4j" rev="1.2.16"/>
    </dependencies>

</ivy-module>

ivysettings.xml

<ivysettings>
  <settings defaultResolver="central" />
  <resolvers>
    <ibiblio name="central" m2compatible="true"/>
  </resolvers>
</ivysettings>


来源:https://stackoverflow.com/questions/27263985/ivy-retrieve-leads-to-module-not-found-org-slf4jslf4j-apislf4j-version

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!