Missing artifact error when adding a dependency in pom.xml file - java

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.

Related

Setting maven to have a framework and other projects that use it

I created a Maven project that i should use as a framework. This framework has some dependencies:
<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>SeleniumJavaFramework</groupId>
<artifactId>SeleniumJavaFramework</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>7</maven.compiler.source>
<maven.compiler.target>7</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-alpha-6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>4.1.6</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
</dependencies>
</project>
I'd like to create other Maven projects, separated from the framework project, that will have their own pom.xml with the framework dependency.
If possible, they should inherit dependencies from the framework 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>RicercaGoogle</groupId>
<artifactId>RicercaGoogle</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>TestOne</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>7</maven.compiler.source>
<maven.compiler.target>7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>SeleniumJavaFramework</groupId>
<artifactId>SeleniumJavaFramework</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>patofmyjar.jar</systemPath>
</dependency>
</dependencies>
</project>
Unfortunately I don't know where to start with the maven settings. I'm not even sure if the pom files are correct. I only know that i can't simply put the jar dependency into the test project and run it. Can you help me out?
Thank you
If you are working at single project, you can create a parent pom that include your TestOne app and Framework as two modules, so you'll have 3 poms (search for maven multimodule project). If your framework is a library for different projects, you need a repository (ie nexus), where your Framework can be deployed to. Then you can use it as a dependency in other projects (dependencies of Framework will be included automatically)
I suggest to follow the maven official guide for learning how inheritance works in maven and adapt this to your logic:
http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance
Problem was that my classes where in the wrong folders.
They were in src/test/java while they had to be in src/main/java.
Also in the test project pom i removed scope and systemPath as suggested by Andrew Fomin
<dependency>
<groupId>SeleniumJavaFramework</groupId>
<artifactId>SeleniumJavaFramework</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
I had an error
Missing artifact SeleniumJavaFramework:SeleniumJavaFramework:jar:0.1.1-SNAPSHOT
because, as you can see, version was wrong.
Thank you all

Maven: Jersey 2 dependency not working

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!

org.apache.olingo path is not resolved even after downloading the dependencies

I am trying to create an OData service using apache olingo V4 (https://olingo.apache.org/doc/odata4/tutorials/read/tutorial_read.html)
But when I am creating an Edm(Entity Data Model) provider class by inheriting the class CsdlAbstractEdmProvider of the package org.apache.olingo.commons.api.edm.provider (https://olingo.apache.org/javadoc/odata4/org/apache/olingo/commons/api/edm/provider/CsdlAbstractEdmProvider.html), getting the error The import org.apache can not be resolved
I understand that, I am missing the necessary library to be included in my project. Though I have created this as maven project and edited the pom.xml file as suggested in the tutorial. Even, to avoid any conflict I am using the same naming conventions for the file as been used in the tutorial.
Please suggest me how to deal with this situation. Feel free to ask about any further clarification about the question. Here I am including 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>my.group.id</groupId>
<artifactId>DemoService</artifactId>
<packaging>war</packaging>
<version>4.0.0</version>
<name>DemoService Maven Webapp</name>
<properties>
<javax.version>2.5</javax.version>
<odata.version>4.0.0</odata.version>
<slf4j.version>1.7.7</slf4j.version>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${javax.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>odata-server-api</artifactId>
<version>${odata.version}</version>
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>odata-server-core</artifactId>
<version>${odata.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>odata-commons-api</artifactId>
<version>${odata.version}</version>
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>odata-commons-core</artifactId>
<version>${odata.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.11</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<finalName>DemoService</finalName>
</build>
</project>
Here is the snapshot of my project folder structure
[Project folder structure]
There was a problem with my maven installation. I installed it separately and set the path variable to C:\ProgramFiles\apache-maven-3.5.0\bin. To be sure you can run mvn -version in command prompt(https://maven.apache.org/install.html).
Thank you

Maven dependencies for Gson not being downloaded

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>

Why maven-war-plugin behaves differently than the standard maven dependency resolving mechanism

Is there a reason maven-war-plugin behaves differently than the standard maven dependency resolving mechanism?
I have a war maven project which has a dependency:
<dependency>
<groupId>GroupA</groupId>
<artifactId>DependencyA</artifactId>
<exclusions>
<exclusion>
<groupId>GroupB</groupId>
<artifactId>DependencyB</artifactId>
</exclusion>
</exclusions>
</dependency>
The above dependency is correctly excluded and I can verify on the dependency hierarchy view.
When I build the war with maven it includes the DependencyB in WEB-INF/lib directory, so I have to explicitly define to exclude it using the maven-war-plugin as so:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<packagingExcludes>
WEB-INF/lib/dependencyB.jar,
</packagingExcludes>
</configuration>
</plugin>
I have to do the above cause conflicts between versions arise on my project.
Why is this happening?
Is there another way to achieve this?
UPDATE
So I created a test case just to showcase you what I mean, if I was not clear enough before.
And the corresponding pom's are as below:
ArtifactA:
<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>GroupA</groupId>
<artifactId>ArtifactA</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>ArtifactA Maven Webapp</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>GroupB</groupId>
<artifactId>ArtifactB</artifactId>
<type>war</type>
<version>0.0.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>GroupC</groupId>
<artifactId>ArtifactC</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<finalName>ArtifactA</finalName>
</build>
ArtifactB
<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>GroupB</groupId>
<artifactId>ArtifactB</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>ArtifactB Maven Webapp</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>GroupC</groupId>
<artifactId>ArtifactC</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>ArtifactB</finalName>
</build>
ArtifactC
<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>GroupC</groupId>
<artifactId>ArtifactC</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ArtifatcC</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
In the dependency Hierarchy in Eclipse, I do not see the dependency ArtifactC.
And when building the ArtifactA and unzipping the .war I get:
As you can see the transitive dependency is included in the .war in the WEB-INF/lib.
I hope this is more clear now.
Some other details to add:
I'm calling maven from eclipse
maven-war-plugin version 2.1.1, also tested 2.5
Maven version 3.0.4 embedded in Eclipse
The problem is not so much that the war plugin handles dependency exclusion differently, but that it handles dependencies of <type>war</type> specially. It creates a war overlay out of these, meaning it takes the whole contents of the war and puts the projects web resources on top. The war dependency really has no transitive dependencies, it already includes all jar files.
If using war overlays is really your intention then using packagingExcludes is the correct solution. If you instead want to depend on the classes in artifact B then you should modify the pom so it creates a separate artifact (using the attachClasses configuration) and depend on this classes artifact. Exclusion of transitive dependencies should then work as with any other jar dependency.
I too have noticed strange behavior with <exclusions>. My best recommendation is to put this in the war project (Project A).
<dependency>
<groupId>GroupC</groupId>
<artifactId>ArtifactC</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
notice the scope provided
I have to do this frequently for commons-logging as something always seems to somehow cause it to be included and its just a pain in the a$$ to go around and mark exclusions everywhere.
The other option is to do this in Project B:
<dependency>
<groupId>GroupC</groupId>
<artifactId>ArtifactC</artifactId>
<version>0.0.1-SNAPSHOT</version>
<optional>true</optional>
</dependency>
Then add the ArtifactC and ArtifactB dependency explicitly where you actually need it (ie deploying B in other places).
notice the optional
Like I said in my comment I don't think its a good idea to rely on <exclusions>. It generally means something is broken. Its particularly bad if your the one causing it.

Categories