How to resolve a pom in the dependencies list? - eclipse

I am very new to Maven and am trying to use it to load the JARs I need for a web project.
I have been using the goal dependency:copy-dependencies and have set the output path to <project>\WEB-INF\libs. This has worked well so far.
I now want to intergrate the latest version of Swagger which has the following POM:
<!-- https://mvnrepository.com/artifact/io.swagger.core.v3/swagger-project -->
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-project</artifactId>
<version>2.0.0-rc4</version>
<type>pom</type>
</dependency>
All this does is to load the POM to the libs folder.
Is it possible to recursively resolve POMs in the dependencies list or have I misunderstood something basic?

As has been said in the comment, take out the pom:
<!-- https://mvnrepository.com/artifact/io.swagger.core.v3/swagger-project -->
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-project</artifactId>
<version>2.0.0-rc4</version>
</dependency>
The default type is jar so you don't need it, other types are pom, war, ear.
Make sure you have your proxy set in your settings.xml, which should be in ~/.m2 directory.

Related

Eclipse Maven dependency jar grayed out, can't import classes from it

I'm helping a friend configure a maven project with m2eclipse for the first time. We're both pretty unfamiliar with it and are encountering an issue where even though a dependency jar is showing up with packages in it under "maven dependencies" in the Project directory, if we try to import anything from any of that jar's packages, it can't find the class.
I noticed that the jars that are having issues are gray and not as opaque as the rest of the jars that are working.
What's strange is if you hover of the class name in the import, it shows a brief description of the class (from the documentation in the jar!) but it won't let me import it. All the other maven dependencies can be imported fine. Any ideas? We can't seem to even find what the darker icon means.
Also, the pom.xml is dead simple:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.something.portal.test</groupId>
<artifactId>PortalFrontEndTests</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>PortalFrontEndTests</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>
<!-- Selenium -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
<!-- TestNG -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
I'm not sure what I'm missing here
open your pom.xml file
check for the name of the grayed out jar file
change
<scope>test</scope>
to
<scope>compile</scope>
I found the issue. It was because I had the class in the source directory instead of the test directory and both of the maven dependencies had been marked as "Visible only to test"
I had the same problem when i used the <scope>test</scope> in the maven pom.
It seems as if the newer Eclipse/Java versions do have a new Attribute :
<classpathentry kind="src" output="target/test-classes" path="src/test/java/...">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
This should be enabled in the Java Build Path Settings:
Image showing "Containts test sources" option from build path menu
After enabling this i got rid of all the compiler errors.
check for your dependency scope in POM file
compile, provided, system and test these were the available test
test -> compile would change your dependencies from grey to white.
If your dependency is for test scope then that dependency is not available for normal use in application whereas compile scope sets that dependency in class path of your project.
I am not sure on the grayed out part. If this is the feature because it suggest that Testing class should be under /test rather /src.
However, solution to your problem is scope of plugin, change it to compile and you will be good to go.
i.e. replace test with compile:
<scope>test</scope>
<scope>compile</scope>
That's it. you will not get any error for import testing packages.
Just removing the Scope will work. I tried as the following:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.0-M1</version>
</dependency>
I am also faced the same problem
set scope to compile or remove scope
open maven dependencies
right click on dependency and click download resources

eclipse maven dependencies pom file

Hi does anybody know where do i need to setup the mahout.version property in order for eclipse to get the latest version of the dependency?
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-core</artifactId>
<version>${mahout.version}</version>
</dependency>
if you have a super pom or parent pom.xml you can make the properties like this :
<properties>
<mahout.version>0.9</mahout.version>
</properties>
Please replace following in your pom.xml of maven build.
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-core</artifactId>
<version>0.8</version>
</dependency>

Maven Dependencies references non existing library

As stated above I have a problem regarding maven. In my current eclipse project I used maven for dependecy management and it worked fine until now.
The project is not working anymore and it states that:
Maven Dependencies references non existing library:
c:\.m2\repository\org\eclipse\lyo\oslc4j\core\oslc4j-core\1.1\oslc4j-core-1.1.jar'
If i check the folder there are files that have the same name as the jar but end on jar.lastUpdated.
I tried maven clean and maven update which did not work. The line in my pom.xml is marked red and states:
Missing artifact org.eclipse.lyo.oslc4j.core:oslc4j-core:jar:1.1
This is the content of my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http:/www.w3.org2001XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.or/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>rtc_oslc_common</groupId>
<artifactId>rtc_oslc_common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
This block is the one with the marker where it states the artifact is missing.
<dependencies>
<dependency>
<groupId>org.eclipse.lyo.oslc4j.core</groupId>
<artifactId>oslc4j-core</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
</project>
I don't know why it is not just reloading the jars and instead stays in this weird state. Help very much appriaciated.
Basically Maven is telling you that it cannot find the dependency you declared in your pom.xml. The fact that there is a file called *.jar.lastUpdated means that Maven tried to download the dependency but wasn't able to fetch it.
First you could try to completely delete the folder containing the *.jar.lastUpdated and run the build again. Maven will then try to download the dependency again. Perhaps it was just a temporary error.
But as this dependency is not available in Maven Central, you may have to add the corresponding repository to your pom.xml.
Sometimes an officially stated dependency configuration is incorrect, too. For example, as of 2015-05-23 the Robolectric site says...
<dependency>
<groupId>org.robolectric</groupId>
<artifactId>robolectric</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
... which gives the same error you describe. After banging my head for a while (of course this was the first time I've ever tried Maven), I ended up checking at Maven Central this URL: http://mvnrepository.com/artifact/org.robolectric/robolectric
Lo and behold, there is no version 3.0. Instead, there are versions "3.0-rc1" and "3.0-rc2". When I changed the dependency to "3.0-rc2", suddenly everything worked.
I got the error like this:
The container 'Maven Dependencies' references non existing library 'G:\m2\repository\org\apache\tomcat\tomcat-embed\7.0.65\tomcat-embed-7.0.65.jar'
I found the tomcat-embed is actually a *.pom file but not a *.jar
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-embed</artifactId>
<version>7.0.65</version>
<type>pom</type>
</dependency>
So I fixed this problem by:
delete tomcat-embed-7.0.65.jar.lastUpdated
copy a *.jar file to dir G:\m2\repository\org\apache\tomcat\tomcat-embed\7.0.65\
renamed to tomcat-embed-7.0.65.jar
But the other way to solve this problem?
Firstly, you repair, intenet problem. after that You must delete folders in maven repository folder. (For me C:\Users\ekomut.m2\repository)
If you have an Internet problem, you can see "*.jar.lastUpdated" .If you don't delete this folder, maven can not try download again.

Maven does not automatically download dependencies

I'm a starter for Maven. I pulled a java maven project from Bitbucket. When compiling the prject Eclipse said "8/6/12 1:39:05 PM EST: Missing artifact com.tinkerpop.blueprints:blueprints-core:jar:1.0:compile":
Maven console:
8/6/12 1:39:03 PM EST: Missing artifact com.tinkerpop.blueprints:blueprints-core:jar:1.0:compile
8/6/12 1:39:05 PM EST: Missing artifact com.tinkerpop.blueprints:blueprints-core:jar:1.0:compile
but when I check the pom.xml file, it is already there in the dependency list, only the Type and Scope fields are empty. Seeing the errors, I try to add this dependency by myself. And it showed like this:
The #1 question is, Why for 1.0 version, blueprints-core only have a .pom file not a .jar file? Does this mean in the remote repository they don't provide the 1.0 version any more? (I found the codes in the project reply on 1.0 version instead of 2.0 version of this Blueprint framework)
The #2 questions is, under what circumstances Maven will not automatically download the jar files for the dependencies added?
This is the original 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/xsd/maven-4.0.0.xsd">
<parent>
<groupId>edu.qut.cs</groupId>
<artifactId>qut-recommender</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../qut-recommender/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>rcmd-common</artifactId>
<packaging>jar</packaging>
<name>QUT Recommender Common Library and Utilty</name>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>11.0.1</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.7.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-ext</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jgrapht</groupId>
<artifactId>jgrapht</artifactId>
<version>0.7.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.tinkerpop.blueprints</groupId>
<artifactId>blueprints-core</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
</dependencies>
</project>
The POM and Jar files of 1.0 version exist. The following picture is the directories and files in the folder of "C:\Users\n8275441.m2\repository\com\tinkerpop\blueprints". BTW, I pulled this project from Bitbucket repository. Is it possible that those 1.0 version files came along with the project in Bitbuckdet?
Based on your information and after checking maven central the problem is based on the version you have selected. Maven Central contains only a version 1.2, 2.0.0 and 2.1.0 but not a version 1.0.
Furthermore if a dependency is given without scope like in your pom:
<dependency>
<groupId>com.tinkerpop.blueprints</groupId>
<artifactId>blueprints-core</artifactId>
<version>1.0</version>
</dependency>
this means default scope which is "compile" (as in the sense of convention over configuration). I would simply suggest to change the version to 2.0.0 or 2.1.0 which should solve the problem.
If you check compiling such project i would suggest to do the first try on command line and not in Eclipse.
If you're wondering what Maven Central offers, mvnrepository.com is your friend.
In this case, there is no 1.0 version: http://mvnrepository.com/artifact/com.tinkerpop.blueprints/blueprints-core
Which leads to the interesting question why m2e reports a POM file for it. I suggest to have a look on your hard disk if the POM file really exists. You can find it (or not) in C:\Users\n8275441\.m2\repository\com\tinkerpop\blueprints\1.0\blueprints-core\
As for question #2: Maven (and m2e as well), will try to download a release (i.e. something that doesn't have SNAPSHOT in the version) only once. If the download fails, Maven will note that and never try again since it assumes that the upstream repositories (Maven Central, for example) heed the Maven rules (so if a repo doesn't have something, it won't have it tomorrow).
For snapshots, Maven will try to download them once per day to get a good balance between keeping you up to date and not wasting your time waiting for some download.

maven deploy exclude

I want to exclude one dependency when I'm doing deploy, I need it when I use the jar locally, but it should not be in deployed jar. is there any way to do it?
It depends on what you mean by "use the jar locally".
If you mean that you don't want the jar to be included in any bundles, you can set the scope of the dependency to provided. This scope is only available on the compilation and test classpath, and is not transitive. A dependency with this scope will not be included in wars/ears.
<dependency>
<groupId>some.groupid</groupId>
<artifactId>my-dependency</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
If you mean you don't want the jar to be bundled into a distribution built with the assembly plugin, you can configure the assembly to exclude a specific dependency.
<profile>
<id>localProfile</id>
<activation>
<property>
<name>!deploy</name>
</property>
</activation>
<dependencies>
<dependency>
...
</dependency>
</dependencies>
</profile>
when i run it with
mvn deploy -D deploy=0
the jar doesnt have that dependency
Maybe a good solution is to set the dependency with a <scope>provided</scope>. This way, the dependency will not be deployed.
However, locally, you will need to add the dependency in your classpath...