Maven Dependency's dependency - maven

In my project I have slf4j-log4j12
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
This version uses log4j 1.2.17. The log4j latest update is 2.11.1.
How can I make my maven project to force use the latest log4j i.e. 2.11.1 version?

Be aware that log4j version 2 is completely incompatible with log4j version 1. You cannot replace like that those version.
To use log4j-2 as backend for slf4j, you will need to replace this dependency by another.
From the page in log4j 2 site, the dependency is linked to the version of slf4j
In your use case, (sf4j 1.7) it is this one:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.11.1</version>
<scope>test</scope>
</dependency>
for slf4j 1.8+ it will be this one:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j18-impl</artifactId>
<version>2.11.1</version>
<scope>test</scope>
</dependency>

Related

Maven doesn't download a slf4j dependency slf4j-log4j12

I try to use
slf4j-log4j12
library, but maven doesn't download the jar. My local .m2 repository shows
enter image description here
I'm using Apache Maven 3.5.4 with Java version: 11.0.15. The dependencies in pom.xml:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-reload4j</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>2.0.3</version>
<type>pom</type>
<scope>test</scope>
</dependency>
What could be the problem? I'm behind corporate firewall and use JFrog antifactory.
I added maven2 repo to pom.xml. Tried Invalidate Cache in IntelliJ and other cleanup I could think of.

How use Log4j methods in log4j2

I am trying to upgrade log4j to log4j2.I am using some methods of log4j1 like removeAllappender(),setName(), these not found in log4j2.
I have included these dependencies:-
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.1</version>
</dependency>
I tried to include bridge also but it fails the build. How can I solve these?
note:-My project is in maven.
**i have also added bridge dependency 1.x to 2.x

How to exclude a dependency from remote mavenpom?

I have a local pom which uses mahout-0.8 dependency. Mahout pom includes hadoop-core dependency with 1.1.2 version. Link to mahout-0.8 pom
But in my project I need the latest hadoop-core, which is 2.2.0 version. As I have read hadoop-core-2.2.0 is built from these dependencies:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-core</artifactId>
<version>2.2.0</version>
</dependency>
So I need to exclude dependency from remote mahout-0.8 dependency. How to exclude this dependency (snipped) or it cannot be done remotely?
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>${hadoop.version}</version>
...
</dependency>
If it cannot be done in such way, would like to know how to integrate mahout pom to my local project.
Many thanks!
Copy the hadoop-core dependency in your second snippet into the dependencyManagement section of your pom. This will manage it to whatever version you specify.
Or, if you really really want to stop it from coming from mahout all together, change your mahout dependency to something like the following:
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout</artifactId>
<version>0.8</version>
<exclusions>
<exclusion>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
</exclusion>
</exclusions>
</dependency>

Apache CXF and Spring dependencies conflict exception

I want to integrate CXF and Spring for a simple JAX-WS. Below is the maven pom file.
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
</dependency>
</dependencies>
When I run the jetty using maven command. It had some exception like this:
spring java.lang.NoSuchMethodError: org.springframework.core.convert.converter.ConverterRegistry.addConverter(Ljava/lang/Class;Ljava/lang/Class;Lorg/springframework/core/convert/converter/Converter;)V
It seems the problem is CXF and Spring dependencies problems. When I go to the target folders and find out there are two version of Spring with the version I specified and the version CXF depend on. 3.0.7?
If I change the spring version to the lower one and it works.
I just wondering are there any way to solve this if I still want to use the latest version of Spring?
I think I find out the reason. I need also to put spring-core as maven dependency. Because the converter in the exception are in the core dependency.
So when the maven jetty run, there are two version of spring, spring-core is using 3.0.7 which is with CXF, and the other are 3.2.3 which is I specified.
I need to keep consistent with spring version in the project.

slf4j-log4j12 not packaged by maven with "runtime" scope

I have a project managed by maven with slf4j-api-1.5.8 and log4j-1.2.14 dependencies.
At runtime, slf4j needs slf4j-log4j12-1.5.8.jar to "bridge" output to log4j.
So in pom.xml , I add this dependency :
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
</dependencies>
</dependencyManagement>
After building (war:war) , log4j-1.2.14.jar and slf4j-api-1.5.8.jar are both added to WEB-INF/lib directory , but I cannot find slf4j-log4j12-1.5.8.jar within!
I then use "Dependency Hierarchy" to check the resolved dependencies , but cannot find slf4j-log4j12 (so it's not packaged into WEB-INF/lib)
What's going wrong here?
environment : maven 3.0-beta1 , m2-eclipse-0.10.0.20100209
The dependency management section is a mechanism for centralizing dependency information, adding a dependency in the dependency management section doesn't make it a dependency of your project by itself, you still need to declare it as dependency:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
</dependencies>

Resources