Maven automatically removes trailing zeroes in dependency version (javax.servlet-api) - java

I am trying to add the javax.servlet-api project to my Maven Java project (see this link for more information about versions for this dependency). I want to add version 3.1.0 to my project. So naturally, I add this dependency to my pom.xml file:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
However, when Maven tries to download the jar/pom files for this artifact, it gets an error because it automatically converts version 3.1.0 to 3.1, which is not its actual version, and it cannot find that version of the artifact in the central Maven repo:
Downloading: http://repo.maven.apache.org/maven2/javax/servlet/javax.servlet-api/3.1/javax.servlet-api-3.1.pom
[WARNING] The POM for javax.servlet:javax.servlet-api:jar:3.1 is missing, no dependency information available
Downloading: http://repo.maven.apache.org/maven2/javax/servlet/javax.servlet-api/3.1/javax.servlet-api-3.1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
...
[ERROR] Failed to execute goal on project my-java-project: Could not resolve dependencies for project com.example.myproject:my-project:war:1.0-SNAPSHOT: Could not find artifact javax.servlet:javax.servlet-api:jar:3.1 in central (http://repo.maven.apache.org/maven2) -> [Help 1]
Does anyone know how I can tell Maven to not strip off trailing zeroes in the version tag of a dependency in my pom.xml file? Any other workaround known?
NOTE: I did check out this SOF post (Maven dependency for Servlet 3.0 API?), but this author's solution was to use a <scope>provided</scope> dependency for servlet-api, which I do not have interest in doing becuase I want to avoid needing to use the provided scope.

it gets an error because it automatically converts version 3.1.0 to 3.1
That is something impossible. Maven will never convert version numbers ( with the exception of snapshots ). It will always download the version that you specify in the pom.xml regardless the version actually exists or not. You can test this by writing a bogus number in the version area of the tag and then fire the mvn install command, you will see that it will try to download that version and then fail.
To debug your problem, first verify that you have the correct maven entry in the pom
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
Secondly , I would advise you to delete the folder ~/.m2/repository/javax/servlet/ to remove any bad jar and thus force maven to re-download all the javax.servlet jars

Related

Pom.XML Maven Build Dependency of POM Only Looking for Jar

GIVEN:
I have an in house tool built with gradle that includes a dependency that is only a POM file which in turn then includes a bunch of other dependencies. No jar for this particular dependency by itself. The tool builds.
I have a maven project with a pom.xml file that I want to include this tool in because of all the company specific methods needed for some processes. I added the dependency with the type of pom and when I build it fails.
ERROR:
[ERROR] Failed to execute goal on project <MYPROJECT>: Could not resolve dependencies for project <MYPROJECT>:jar:0.0.326: <com.pom.only.dependency>:jar:7.0 was not found in <Company Repo where this POM file exists> during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of <company repo> has elapsed or updates are forced
REQUEST:
I have tried making the tool a fat jar in the hopes it would not need this. But it does. The my project builds without this tool jar so I know it is this jar that brings in the dependency. I just have no idea how to resolve this.
ALMOST CODE EXAMPLE
Because of company specific, I can not put the exact POM code but I can put what it looks like removing company specific stuff.
<dependency>
<groupId>com.group</groupId>
<artifactId>tools-app</artifactId>
<version>1.0.11</version>
</dependency>
<dependency>
<groupId>com.group</groupId>
<artifactId>pom only dependency</artifactId>
<version>7.0</version>
<type>pom</type>
</dependency>
So tools app is the one that I am pulling it. It is the gradle build and uses the pom only dependency without any issue. If I pull this into a gradle app it works fine and builds. However, in the app that has this in the pom, if fails for above. So I add the dependency for the pom only dependency and mark it as type pom but still get the error.
So for my situation (and not the best solution), I went into the dependency that has only a pom and pulled the dependencies out of there and built. It worked. But feel there should be a way to make it work without having to do this.

Limit downloading of maven dependencies when version in open end range

I have a multi module maven project with a parent POM which defines a few common dependencies as part of the dependency management as follows:
<dependency>
<groupId>com.example</groupId>
<artifactId>example-commons-core</artifactId>
<version>(1.2,)</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>example-commons-logging</artifactId>
<version>(1.3,)</version>
</dependency>
I have added this version format to avoid permanently update versions in the POM, when a new version of the core library is created.
My problem is that by each maven build, maven will check up all repositories for new version for each dependency I got following log entries:
Downloading from snapshots: https://example.com/repository/snapshots/com.example/example-commons-core/maven-metadata.xml
Downloading from release: https://example.com/repository/release/com.example/example-commons-core/maven-metadata.xml
Downloading from 3rdparty: https://example.com/repository/3rdparty/com.example/example-commons-core/maven-metadata.xml
Downloading from central: https://repo1.maven.org/maven2/com.example/example-commons-core/maven-metadata.xml
My question is can I do the checks for example monthly?
How to avoid that maven tries to check my own dependencies on maven central repository?
The modern way to solve the problem is to avoid version ranges but use the versions maven plugin (like versions:use-latest-releases).

No java classes in downloaded Selenium jar

I am trying to upgrade to Selenum 4.0.0-alpha-6 (same issue happens also with version 3.141.59) which seems to be available in Maven repository. I tried first to add this dependency to my pom.xml:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-alpha-6</version>
</dependency>
The version appears red in IntelliJ which for some reason sees 3.12.0 as the last available version. I know what version IntelliJ sees because I can hit CTRL-space inside the <version> tag.
Running mvn install also complains that the version is not available. So my first question is why do Intellij and Maven not see the latest versions of Selenium?
I reverted to downloading the jar file directly from mvnrepository (that is from here) and adding it to my local repository as follows:
mvn install:install-file -Dfile=selenium-java-4.0.0-alpha-6.jar
-DgroupId=org.seleniumhq.selenium -DartifactId=selenium-java
-Dversion=4.0.0-alpha-6 -Dpackaging=jar -DgeneratePom=true
The jar appears now in my local repo, the Maven dependency does not appear red anymore, but all Selenium-related references in my project appear red. Examining the downloaded jar file reveals that it contains no Java classes:
C:\Development\Java\Selenium>jar tf selenium-java-4.0.0-alpha-6.jar
META-INF/
META-INF/MANIFEST.MF
META-INF/versions/9/
META-INF/versions/9/module-info.class
Any idea what I am missing?
Update: I have added a small project in GitHub that demonstrates the problem. The pom just has the Selenium dependency.
Just running mvn install results in the error below. So this is not just a problem with IntelliJ:
[ERROR] Failed to execute goal on project MySeleniumProject: Could not resolve dependencies for project com.my:MySeleniumProject:jar:1.0-SNAPSHOT: Failed to collect dependencies for [org.seleniumhq.selenium:selenium-java:jar:3.141.59 (compile)]: Failed to read artifact descriptor for org.seleniumhq.selenium:selenium-ja
va:jar:3.141.59: Could not transfer artifact org.seleniumhq.selenium:selenium-java:pom:3.141.59 from/to central (http://repo.maven.apache.org/maven2): Failed to
transfer file: http://repo.maven.apache.org/maven2/org/seleniumhq/selenium/selenium-java/3.141.59/selenium-java-3.141.59.pom. Return code is: 501 , ReasonPhras
e:HTTPS Required.
Try use stable older version
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
Check also, if you have other errors in pom, and have proper java version
I think your project is correct and problem is with maven configuration. Use commandline to see what maven version you have? maven -v. Try use mvn dependency:resolve on the project - from command line
The problem is resolved by upgrading maven. I had Maven 3.0.5, and uprading to 3.6.3 resolved the dependency successfully.

Maven error: Package matlabcontrol does not exist

I've added the following .jars as external jars to Libraries.
C:\Users\user\Downloads\common-lang3.jar\common-lang3.jar
C:\Users\user\Downloads\matlabcontrol\matlabcontrol-4.1.0.jar
However, during clean install of a Maven build in Eclipse, I get the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project com.webapp: Compilation failure: Compilation failure:
[ERROR] /C:/Users/user/workspace/GetTimeDistance/src/com/MatLabClass.java:[4,21] package matlabcontrol does not exist
[ERROR] /C:/Users/user/workspace/GetTimeDistance/src/com/MatLabClass.java:[7,40] package org.apache.commons.lang3.builder does not exist
The source of the jars in the library are pointing to the correct jars.
I am able to use the code in the jars in my own code.
When hoovering over the import, I get the following Note:
Note: This element neither has attached source nor attached Javadoc and hence no Javadoc could be found.
Any idea's? I already updated the Maven project several times.
EDIT:
I've added:
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.matlabcontrol</groupId>
<artifactId>matlabcontrol</artifactId>
<version>4.1.0</version>
</dependency>`
To the .pom file. This gives the following warning:
[WARNING] The POM for org.matlabcontrol:matlabcontrol:jar:4.1.0 is missing, no dependency information available.
When you run from maven, all the dependent jars will be referenced from maven repository only. It wont take any external libraries or jars. You define maven dependencies of the required jars in your pom.xml. If you want the local jars to be copied into your maven repository, below is the cmd mvn install:install-file -Dfile=your_local_path_of_jar -DgroupId=your_groupID -DartifactId=your_artifcat_id -Dversion=your_version -Dpackaging=jar
I assume you work with eclispe and added the external jars to the "Build path" of your Project properties? The "Build path" is used by the eclipse IDE to resolve classes within the workspace, and has no influence on which libraries are used when performing a maven build. Most likely, you missed to define commons-lang and matlabcontrol as dependencies in your pom.xml file...

How to build a project on github with pom.xml

This might be a naive question, so pardon me but I am new to maven.
I want to build a jar of project present on github. The project has a pom.xml file and additionally mentions in
Installation Note:
Releases are distributed on Maven central:
<dependency>
<groupId>some_grp_id</groupId>
<artifactId>all</artifactId>
<version>1.1.2</version>
<type>pom</type>
</dependency>
Am I suppose to add above in the existing pom.xml file ??
I an cloning the project on my desktop and then executing "mvn package".
If you want to simply use the library then you only have to add the above dependency to your pom.xml. Maven is doing all the rest for you (downloading the .jar-file).
If you really want to use the source code you have to do a
mvn install
on the checked out code. And also have to include the dependency in your own pom.xml.

Categories