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>
Related
When I try to convert a project from maven/sbt to Gradle:
https://github.com/tek/splain/blob/nexusRelease/Dev1/build.gradle.kts
I found a few problems, when comparing the new published pom file (by gradle):
...
<modelVersion>4.0.0</modelVersion>
<groupId>io.tryp</groupId>
<artifactId>splain_2.13.6</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>2.13.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.13.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.tryp</groupId>
<artifactId>splain_2.13.6</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
</dependencies>
</project>
with the old one (by sbt):
...
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>2.13.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.13.5</version>
</dependency>
<dependency>
<groupId>com.chuusai</groupId>
<artifactId>shapeless_2.13</artifactId>
<version>2.3.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>dev.zio</groupId>
<artifactId>zio_2.13</artifactId>
<version>1.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.specs2</groupId>
<artifactId>specs2-core_2.13</artifactId>
<version>4.5.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
The pom file generated by gradle has a self-referential dependency to itself. This has caused nexus publishing to fail the sanity check. My questions are:
should this be illegal? Why is gradle permitting this?
why was it generated?
Gradle has a few other problems (like the deprecation of the provided scope) but so far this is the most serious of them all.
Fixed, turns out the problem was caused by "java-test-fixtures" plugin.
Test fixture doesn't have a maven scope counterpart, so by default their dependencies are merged into compile scope dependencies when publishing. The problem disappeared once I disabled their publishing:
val javaComponent = components["java"] as AdhocComponentWithVariants
from(javaComponent)
javaComponent.withVariantsFromConfiguration(configurations["testFixturesApiElements"]) { skip() }
javaComponent.withVariantsFromConfiguration(configurations["testFixturesRuntimeElements"]) { skip() }
I am using Maven to download aws-java-sdk dependency for version 1.11.23, though in Maven repository I find all historical versions till most recent ones; i.e. aws-java-sdk-sqs downloaded versions (1.9.0 to 1.11.642) any idea why is that and how can I limit to only the version specified for aws-java-sdk artifact?
This "dependency loop" is a problem with some older versions of aws-lambda-java-events, which is probably a dependency of your dependency.
Try updating or your dependencies to the latest, or overriding aws-lambda-java-events to at least 2.2.7:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>2.2.7</version>
</dependency>
For me, After specifying the BOM of AWS SDK in the dependencyManagement section & the version I would like to use, The historical downloads were stopped. Below are my dependencies.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.10.6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
I created a project (with Maven 3.5.4) with just:
<project ... >
....
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.23</version>
</dependency>
</dependencies>
</project>
All of ~/.m2/repository/com/amazonaws/* (as declared in aws-java-sdks POM) contain just the sub-directory /1.11.23.
UPDATE
To exclude dependencies of your dependencies see Introduction to the Dependency Mechanism, Transitive Dependencies:
Excluded dependencies - If project X depends on project Y, and project Y depends on project Z, the owner of project X can explicitly exclude project Z as a dependency, using the "exclusion" element.
IDE: Intellij IDEA 2018.3
project only one module
dependency:
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.2</version>
</dependency>
</dependencies>
I can use #Slf4j but why cannot find Logger
Add below dependency in your pom file. You are missing dependency. To use the slf4j logger its respective dependency should be present. Hope this solves your problem.
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.24</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.24</version>
</dependency>
Can I download the whole .m2 folder from the internet in place of downloading single jar file?
Remember...
Over the classical way (put a dependency inside a pom and delegate to maven the download)
You have two way to copy a jar into m2
1: The "manual one" just download the jar an put inside the file inside .m2 under the correct path..
2: The official one----> http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
I'm not understanding ...
If I've to make Spring application ...
I put all the dependencies inside my pom.xml .... like this:
<?xml version="1.0" encoding="UTF-8"?>
<!-- A project with Spring MVC, JPA and Hibernate SessionFactory -->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>MavenWeb</groupId>
<artifactId>MavenWeb</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<description></description>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.3.Final</version>
</dependency>
<!-- dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId>
<version>1.4.2</version> </dependency -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.10</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>20030825.184428</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>20030825.183949</version>
</dependency>
</dependencies>
<properties>
<org.springframework.version>3.0.2.RELEASE</org.springframework.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.1</version>
</plugin>
</plugins>
</build>
</project>
When I run the Maven install, maven downloads from the remote central repository to the jar it needs to run the application...
in this way you've downloaded all the jars you need inside your .m2 folder...
That's the usual use of Maven dependencies management ....
but if it's does not help you, maybe I'm not understanding your problem...
If jars are missing which you placed in pom.xml and you want to download, then Right click on your project and run as "Maven Install" it will download the missing jars.
Maybe the actual JAR file you are looking for is not provided in the release, but the POM file is. In that case, until you explicitly tell Maven to use the BOM file to import the needed library, the former will only set up a correct folder hierarchy in your .m2 repository, but with nothing interesting in it.
See the official documentation for the correct lines of code to do so. Here is an example dealing with the org.codehaus.groovy:groovy-all:2.5.9 library (see the top-right item for the Apache Maven lines of code).
I have this maven hierachy :
sim-java
ejb
web
log4j
...
ejb, web and log4j are modules of sim-java and each of these modules refer to sim-java by parent tag.
I would like to create a log4j module and include it as dependency in sim-java so log4j will be present as dependency in ejb and web modules.
Basically, my pom.xml inside sim-java contains this :
<dependencies>
<dependency>
<groupId>com.sim</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
(scope is provided as I have an ear module which will include com.sim:log4j in ear file).
Now, my pom.xml inside my log4j module is this one :
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
I have this build error :
30/10/12 18:56:07 CET: Build errors for log4j; org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project log4j: Could not resolve dependencies for project com.sim:log4j:jar:0.0.1-SNAPSHOT: Could not find artifact com.sim:log4j:jar:0.0.1-SNAPSHOT
I thought that there was some dependency problem since sim-java use com.sim.log4j as transitive dependency, so I tested that inside log4j pom.xml :
<dependencies>
<dependency>
<groupId>com.sim</groupId>
<artifactId>sim-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>com.sim</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
30/10/12 18:59:22 CET: [WARN] The POM for com.sim:log4j:jar:0.0.1-SNAPSHOT is missing, no dependency information available
30/10/12 18:59:22 CET: Missing artifact com.sim:log4j:jar:0.0.1-SNAPSHOT:provided
30/10/12 18:59:22 CET: Missing artifact com.sim:log4j:jar:0.0.1-SNAPSHOT:provided
30/10/12 18:59:22 CET: Missing artifact com.sim:log4j:jar:0.0.1-SNAPSHOT:provided
Perhaps including com.sim.log4j inside modules (ejb, web etc...) would work but I want to use transitive dependency via sim-java project.
How to do this please ?
Olivier
You cannot have the dependency on com.sim:log4j in the parent pom. That dependency will be inherited in the children meaning that com.sim:log4j will depend on itself.
Instead create a <dependencyManagement/> in the parent pom and then declare the use of com.sim:log4j in the children that needs it, here it is web and ejb.
Parent pom:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.sim</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
Web and Ejb pom:
<dependencies>
<dependency>
<groupId>com.sim</groupId>
<artifactId>log4j</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
Edit
You can still have a transitive dependency by only having the dependency on the log4j module from the ejb project. The web project will then have a dependency on the ejb project and the log4j will be a transitive dependency.