Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j2 with apache Ivy dependancy management unable to resolve log4j-api-java9

Tags:

java

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:

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>

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).

like image 314
Scott Neville Avatar asked Nov 08 '22 04:11

Scott Neville


1 Answers

Adding dependency configuration to split build from test dependencies resolve the issue for me:

In the 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>

In build.xml to resolve dependencies:

<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>

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/

Example repository which I use as a Template

like image 117
Quintin Henn Avatar answered Nov 15 '22 11:11

Quintin Henn