I am new to maven and jersey and try to put a dependency of jersey into my pom.xml.
Regarding
http://search.maven.org/#artifactdetails%7Corg.glassfish.jersey%7Cproject%7C2.27%7Cpom
the dependency should be
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>project</artifactId>
<version>2.27</version>
</dependency>
But if I put that in the pom, then I get an error.
[ERROR] Failed to execute goal on project mytest: Could not resolve dependencies for project mytest:mytest:jar:1.0-SNAPSHOT: Could not find artifact org.glassfish.jersey:project:jar:2.27 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
I created the project completely new.
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -DgroupId=mytest -DartifactId=mytest
Thats my pom.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mytest</groupId>
<artifactId>mytest</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>mytest</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>project</artifactId>
<version>2.27</version>
</dependency>
</dependencies>
</project>
Whats the problem??
Thanks for help!
Related
I got a missing artifact error when adding a dependency.
The error I got is this:
Missing artifact com.azure:azure-security-keyvault-secrets:jar:4.1.0
This is my pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.companyname.encryptionkeyclient</groupId>
<artifactId>encryptionkeyclient</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>encryptionkeyclient</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-security-keyvault-secrets</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
</project>
I suppose the reason is that the package is not available yet on maven, however, the package is available already https://mvnrepository.com/artifact/com.azure/azure-security-keyvault-secrets/4.1.0 .
So I don't know what I am missing here, can anyone help? Thanks.
The mirror address you provided has "azure-security-keyvault-secrets" jar and in my project it download this jar successfully(with the same mirror address).
You can remove all of the packages under the "repository" folder and save the pom.xml, the project will download all of the packages again. The issue will go away.
I just got in issue related to Maven and Dependent JAR version. I create following project to analyze issue.
I created App_1.jar which is using spring version 4.2.9.
I created App_2.jar which is using spring version 4.3.4.
I created App_3.jar which is using spring version 4.3.6.
I created App_Main.war which will App_1.jar, App_2.jar, App_3.jar.
According to maven if you use different version it will use the latest one but in my case it using the spring version of jar which i included first which is App_1.jar and its version is 4.2.9.
Here is the code.
**App_1 POM.xml**
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ksh</groupId>
<artifactId>App_1</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>App_1</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.9.RELEASE</version>
</dependency>
</dependencies>
</project>
**App_2 POM.xml**
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ksh</groupId>
<artifactId>App_2</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>App_2</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>
</dependencies>
</project>
**App_3 POM.xml**
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ksh</groupId>
<artifactId>App_3</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>App_3</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
</dependencies>
</project>
App_Main POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>App_Main</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>App_Main Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>com.ksh</groupId>
<artifactId>App_1</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.ksh</groupId>
<artifactId>App_2</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.ksh</groupId>
<artifactId>App_3</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<finalName>App_Main</finalName>
</build>
</project>
Where did you read maven use the latest one?
For transitives dependencies Maven uses a "nearest-wins" strategy to resolves version conflicts, and that means it will use the version of the closest dependency to your project in the tree of dependencies.
Maven transitive dependencies
One possible solution is use the <dependencyManagement> to resolve your conflicts.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>spring_context_version_you_want_to_use</version>
</dependency>
</dependencies>
</dependencyManagement>
Maven dependency managament
You can check your tree of dependencies with the command:
mvn dependency:tree -Dverbose -Dincludes=your-jar
Resolving conflicts using the dependency tree
I created this example POM file so that I do not need the dependency versions replicated in each child project. My requirement is that the thirdparty version need not be provided for each project. Each project should inherit the library versions from the bom file. I created the example based on the documentation of Maven dependencies. My maven version is Apache Maven 3.2.5
I am getting the error below
[INFO] Scanning for projects...
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project org.test.testapp:test-app:1.0-SNAPSHOT (/Users/skoya/workspace/test-app/pom.xml) has 2 errors
[ERROR] 'dependencies.dependency.version' for junit:junit:jar is missing. # line 22, column 17
[ERROR] 'dependencies.dependency.version' for commons-cli:commons-cli:jar is missing. # line 26, column 17
root bom pom file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test</groupId>
<artifactId>bom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>test-dependencies-bom</name>
<url>http://myorg.org</url>
<properties>
<commons-cli.version>1.3</commons-cli.version>
<junit.version>3.8.1</junit.version>
</properties>
<modules>
<module>test-dependencies</module>
</modules>
</project>
test-dependencies/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test</groupId>
<artifactId>test-parent-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>test-parent-pom</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.test</groupId>
<artifactId>bom</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<prerequisites>
<maven>3.0.0</maven>
</prerequisites>
<dependencies>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>${commons-cli.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
</project>
Maven project files referencing the bom file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test.testapp</groupId>
<artifactId>test-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>test-app</name>
<url>http://maven.apache.org</url>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.test</groupId>
<artifactId>bom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>
</dependencies>
</project>
There are 2 issues:
For importing of dependencies, the imported pom project (test-dependencies/pom.xml) should define the dependencies to import in a <dependencyManagement> section, not just <dependencies> as was done in your original sample.
The project that imports that pom needs to import the project that declares the dependencies (test-dependencies/pom.xml), not the parent pom.xml.
I fixed this by making the following changes.
test-dependencies/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test</groupId>
<artifactId>test-parent-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>test-parent-pom</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.test</groupId>
<artifactId>bom</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<prerequisites>
<maven>3.0.0</maven>
</prerequisites>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>${commons-cli.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Maven project files referencing the bom file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test.testapp</groupId>
<artifactId>test-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>test-app</name>
<url>http://maven.apache.org</url>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.test</groupId>
<artifactId>test-parent-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>
</dependencies>
</project>
After that, I was able to build and verify that the project importing the pom was bringing in the expected dependencies:
mvn dependency:tree
...
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # test-app ---
[INFO] org.test.testapp:test-app:jar:1.0-SNAPSHOT
[INFO] +- junit:junit:jar:3.8.1:compile
[INFO] \- commons-cli:commons-cli:jar:1.3:compile
Note that it still successfully pulled the version numbers as defined in properties from the parent pom.xml. This a perfectly valid way to structure the project. It just needed the 2 adjustments I described.
I'm not that familiar with using Maven, so it is likely a user error in this case. My understanding of the elements in the POM file is that any "dependency" that is listed here will be retrieved from the Central Repository based upon the scope of the dependency. In my case, I'm attempting to use the Gson library from Google. It is located on the Central Repository and so it should be reachable by the Maven tool. I've executed "mvn -X compile" to determine if I can see the dependencies in the import. But I don't see them being downloaded during the compile. Any ideas as to what could be wrong with my configuration?
Below is my POM for my project.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.acumen.app</groupId>
<artifactId>CatalogConverter</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>CatalogConverter</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
I am building a Dropwizard project.
(start with:https://dropwizard.github.io/dropwizard/getting-started.html)
I create a project in eclipse, but don't understand why I get "cannot be resolved".
This is errors:
This is pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo.bar.app</groupId>
<artifactId>mvn-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>mvn-test</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<dropwizard.version>INSERT VERSION HERE</dropwizard.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>${dropwizard.version}</version>
</dependency>
</dependencies>
</project>
Any one can help?
I don't know how to import the package, i really have no idea with maven dependency.
Thanks.
You have to define ${dropwizard.version} tag between in pom.xml like this :
<properties>
<dropwizard.version>0.7.0</dropwizard.version>
</properties>
You have to insert your specific dropwizard.version:
<dropwizard.version>**INSERT VERSION HERE**</dropwizard.version>
so it can be used in your pom:
<version>${dropwizard.version}</version>