问题描述
当尝试将apache log4j2与ivy构建管理工具一起使用时,在尝试解决依赖关系时出现以下错误:
When trying to use apache log4j2 with the ivy build management tool I get the following error when trying to resolve dependencies:
:: problems summary ::
:::: WARNINGS
module not found: org.apache.logging.log4j#log4j-api-java9;2.11.0
==== local: tried
C:\Users\Scott Neville\.ivy2\local\org.apache.logging.log4j\log4j-api-java9\2.11.0\ivys\ivy.xml
-- artifact org.apache.logging.log4j#log4j-api-java9;2.11.0!log4j-api-java9.zip:
C:\Users\Scott Neville\.ivy2\local\org.apache.logging.log4j\log4j-api-java9\2.11.0\zips\log4j-api-java9.zip
==== shared: tried
C:\Users\Scott Neville\.ivy2\shared\org.apache.logging.log4j\log4j-api-java9\2.11.0\ivys\ivy.xml
-- artifact org.apache.logging.log4j#log4j-api-java9;2.11.0!log4j-api-java9.zip:
C:\Users\Scott Neville\.ivy2\shared\org.apache.logging.log4j\log4j-api-java9\2.11.0\zips\log4j-api-java9.zip
==== public: tried
https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-api-java9/2.11.0/log4j-api-java9-2.11.0.pom
-- artifact org.apache.logging.log4j#log4j-api-java9;2.11.0!log4j-api-java9.zip:
https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-api-java9/2.11.0/log4j-api-java9-2.11.0.zip
module not found: org.apache.logging.log4j#log4j-core-java9;2.11.0
==== local: tried
C:\Users\Scott Neville\.ivy2\local\org.apache.logging.log4j\log4j-core-java9\2.11.0\ivys\ivy.xml
-- artifact org.apache.logging.log4j#log4j-core-java9;2.11.0!log4j-core-java9.zip:
C:\Users\Scott Neville\.ivy2\local\org.apache.logging.log4j\log4j-core-java9\2.11.0\zips\log4j-core-java9.zip
==== shared: tried
C:\Users\Scott Neville\.ivy2\shared\org.apache.logging.log4j\log4j-core-java9\2.11.0\ivys\ivy.xml
-- artifact org.apache.logging.log4j#log4j-core-java9;2.11.0!log4j-core-java9.zip:
C:\Users\Scott Neville\.ivy2\shared\org.apache.logging.log4j\log4j-core-java9\2.11.0\zips\log4j-core-java9.zip
==== public: tried
https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-core-java9/2.11.0/log4j-core-java9-2.11.0.pom
-- artifact org.apache.logging.log4j#log4j-core-java9;2.11.0!log4j-core-java9.zip:
https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-core-java9/2.11.0/log4j-core-java9-2.11.0.zip
::::::::::::::::::::::::::::::::::::::::::::::
:: UNRESOLVED DEPENDENCIES ::
::::::::::::::::::::::::::::::::::::::::::::::
:: org.apache.logging.log4j#log4j-api-java9;2.11.0: not found
:: org.apache.logging.log4j#log4j-core-java9;2.11.0: not found
::::::::::::::::::::::::::::::::::::::::::::::
:: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS
C:\Users\Scott Neville\Documents\fh\running_app\backend\build.xml:77: impossible to resolve dependencies:
这使用的是以下内容的ivy.xml:
This is using a ivy.xml of:
<ivy-module version="2.0">
<info organisation="uk.co.worldsofwar" module="sipsoc"/>
<dependencies>
<dependency org="org.eclipse.jetty" name="jetty-http" rev="9.4.9.v20180320"/>
<dependency org="org.eclipse.jetty" name="jetty-annotations" rev="9.4.9.v20180320" />
<dependency org="org.eclipse.jetty" name="jetty-webapp" rev="9.4.9.v20180320" />
<dependency org="org.freemarker" name="freemarker" rev="2.3.28" />
<dependency org="org.glassfish.jersey.core" name="jersey-server" rev="2.27" />
<dependency org="org.glassfish.jersey.containers" name="jersey-container-servlet" rev="2.27" />
<dependency org="org.glassfish.jersey.media" name="jersey-media-json-jackson" rev="2.27" />
<dependency org="com.auth0" name="java-jwt" rev="3.3.0" />
<dependency org="com.zaxxer" name="HikariCP" rev="3.1.0" />
<dependency org="org.postgresql" name="postgresql" rev="42.2.2" />
<dependency org="org.apache.logging.log4j" name="log4j-api" rev="2.11.0" />
<dependency org="org.apache.logging.log4j" name="log4j-core" rev="2.11.0" />
<exclude org="*" ext="*" type="source" />
<exclude org="*" ext="*" type="javadoc" />
<exclude org="*" ext="*" type="tests" />
</dependencies>
</ivy-module>
这里没有特殊的ivysettings.xml,只有默认值可以从公共仓库中收集.依赖关系解析仅通过使用非常标准的ant即可完成. Java运行时版本为8(JDK也是如此).
There is no special ivysettings.xml in play, just the defaults to collect from the public repos. The dependency resolution is done through ant just using a very standard . The Java Runtime is version 8 (as is the JDK).
推荐答案
添加依赖项配置以将构建与测试依赖项分离开来为我解决了这个问题:
Adding dependency configuration to split build from test dependencies resolve the issue for me:
在 ivy.xml
<configurations>
<conf name="build" description="development dependencies"/>
<conf name="test" extends="build" visibility="private" description="testing dependencies"/>
</configurations>
<dependencies>
<dependency org="org.apache.commons" name="commons-lang3" rev="3.9" conf="build->default"/>
<dependency org="org.apache.logging.log4j" name="log4j-core" rev="2.11.1" conf="build->default"/>
<dependency org="org.apache.logging.log4j" name="log4j-api" rev="2.11.1" conf="build->default"/>
<dependency org="junit" name="junit" rev="4.12" conf="test->default"/>
<dependency org="org.hamcrest" name="hamcrest" rev="2.1" conf="test->default"/>
</dependencies>
在 build.xml 中解决依赖关系:
<target name="resolve" depends="init-ivy" description="resolve project dependencies">
<ivy:resolve file="${ivy.file}"/>
<ivy:retrieve sync="true" type="jar, bundle" pattern="lib/[conf]/[artifact].[ext]"/>
</target>
这会将依赖项放在文件夹结构中,以便蚂蚁轻松地独立编译测试和构建源代码:
./lib/build/
./lib/test/
This will place the dependencies in a folder structure that is easy for ant to compile test and build sources independently:
./lib/build/
./lib/test/
示例存储库模板
这篇关于具有Apache Ivy依赖关系管理的Log4j2无法解析log4j-api-java9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!