Maven dependencies for Gson not being downloaded - java

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>

Related

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

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.

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!

Why I get cannot be resolved with maven 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>

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.

building dependencies for Apache Spark on Eclipse

I would like to use eclipse for an Apache Spark project, but building dependencies appears not to work. I keep getting
"Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (execution: default-descriptor, phase: generate-resources)"
Following the directions on the Apache spark site, https://spark.apache.org/docs/latest/programming-guide.html
I am running CDH5 cluster. using maven. Here is my generated 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.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.1.0</version>
<packaging>jar</packaging>
<name>spark-core_2.10</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
</dependency>
<repositories>
<repository>
<id>Cloudera repository</id>
<url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
I am a new Maven/POM user. How do i solve this issue and stop getting errors in my java code?
The error message seems to be related to m2e plugin. Take a look https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html.
However the pom you expose is strange, the groupId and artifactId should be related to the path and name of your project, and not to the dependency that you try to use (in this case, spark-core_2.10).

Categories