maven dependency version issue - java

Am using a kafka-client dependency in my project abc-bus-api. The version is 2.1.0. See below.
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.1.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
Now this above project is a dependency in another project abc-lib. Here i see a different kafka-client version than what i have specified in my abc-bus-api. See below.
maven tree in STS (for kafka):
Any guess what am doing wrong here.

Related

Not able to exclude transitive dependencies from a dependency whose type is zip

I have this dependency in my pom.xml
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-ri</artifactId>
<version>2.3.4</version>
<type>zip</type>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
jaxws-ri is added as zip in my dependencies. I see a strange behavior as the above dependency is not excluding any transitive dependencies. Am I doing anything wrong here?
I have tried all the ways of exclusions, but nothing is working for me. Can someone please help me here

After updating to latest Spring boot version, spring-boot-starter-parent 2.6.2, my tests stop executing

I have updated the Spring boot version to 2.6.2 from 2.3.12.RELEASE to incorporate log4j change. Now when I executed mvn clean install to build my code, it is executing only one unit test. I have a test suite of around 423 tests that are all executing and passing with 2.3.12.RELEASE. But now even tests are not executing fine. I haven't seen any such incident reported so I am reporting one.
I am executing my tests with PowerMockRunner
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<type>pom</type>
</dependency>
PowerMock dependencies
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
Starting from Springboot 2.4 they removed JUnit4. If you're using JUnit4 you need to add this dependency in your pom:
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
What version of maven you are using and have you use the junit maven plugin.

log4j-slf4j-impl cannot be present with log4j-to-slf4j --- after adding graphql dependency to pom

Im trying mess around with graph ql and integrating it with our existing project. Im following this tutorial since our project is java with spring framework
but after adding the dependencies
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>5.0.2</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-tools</artifactId>
<version>5.2.4</version>
</dependency>
and trying to start my project i get an error
Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl
cannot be present with log4j-to-slf4j
I have found similar post here, and here
Which lead me to attempt to add exclusions but that did NOT help
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>5.0.2</version>
<exclusions>
<exclusion>
<groupId>log4j-slf4j-impl</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>log4j-to-slf4j</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
Excluded dependencies groupId seems wrong. Changing excluded groupId's to org.apache.logging.log4j may solve your problem.
i ended up using
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java</artifactId>
<version>5.0.2</version>
</dependency>

Maven is behaving differently on diffrent system with same pom configuration

I am working on project with my friends in which there are lot of dependencies which are required by lot of modules.
Scenario is like this :-
i am using datastax drivers for apache_cassandra and spark_cassandra_connector which requires different versions of io.netty modules.
spark_cassandra_connector requires cassandra-driver-core which i am already using in my project.
First problem arrived on my friend's laptop which was some netty-epoll error that it didn't find some method although mine was working fine without any error.(same pom.xml)
After working on error we found out there were different versions of io.netty which was used by project dependencies which may be causing the error.
so we used global version of io.netty modules that is :-
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<version>${netty.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
That Problem was fixed .
Now same method not found error is happening in my friends laptop with cassandra-driver-core . so we decided to use cassandra drivers globally
that is :-
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>${cassandra-driver.version}</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-extras</artifactId>
<version>${cassandra-driver.version}</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>${cassandra-driver.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
which is not working.
i have tried excluding cassandra-driver-core from spark connectors
<dependency>
<groupId>com.datastax.spark</groupId>
<artifactId>spark-cassandra-connector-java_2.10</artifactId>
<version>${spark.version}</version>
<exclusions>
<exclusion>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.datastax.spark</groupId>
<artifactId>spark-cassandra-connector_2.10</artifactId>
<version>${spark.version}</version>
<exclusions>
<exclusion>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
</exclusion>
</exclusions>
</dependency>
which also didn't work and this problem is happening on friends system not mine.
is there any thing i need to know about maven or does any body knows why it is happening version i am using has that method.
why other system is not picking up that version or overriding other version which is used by spark module.
i have checked dependency tree on both systems in verbose which shows the same output (in case maven is picking up another version on other system but which is not case also)
i have tried cleaning the .m2 folder on other system which also didn't work.
what can be the solution ??

Getting Failedto load class org.slf4j.impl.StaticLoggerBinder even though I seem to have bindings with my Maven Project

So I searched through and found this problem all over Stack Overflow, and the solution is usually IDE related (You need an external Version of Maven!), wrong version of the loggers (Tried the newest ones), and lastly the lack of choosing a binder.
So I have a Maven project with the following dependencies for my logging needs:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.2</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>runtime</scope>
<version>1.0.9</version>
</dependency>
Even though I have a bound logger in there (Two in fact, slf4j and Logback), whenever I compile on my computer or push it to compile on my Jenkins box I get the:
Failedto load class org.slf4j.impl.StaticLoggerBinder
for every one of my modules. Any possible solutions to try would be appreciated.

Categories

Resources