Get latest version jar from local repository - java

I have some non maven jars in .m2 local repository. Whenever there is a change in the non maven project, I run the build and generate a newer version of jar in the repository. Is it possible to ask maven to get the latest version of jar from the local repository without explicitly mentioning the version of the dependency in pom.xml ? What would be the suggested approach to do this ?

How do the files get to the repository? If you install the files with maven install and use a SNAPSHOT version the maven build will generally use the newest version. If you are using a different manual versioning like 1.2.3, 1.2.4 and so on you can use an open interval in the pom like
<dependency>
<groupId>yourGroup</group>
<artifactId>yourArtifact</artifactId>
<version>[1.2.3,)</version>
</dependency>
There is also a lot of documentation on this topic i.e. How do I tell Maven to use the latest version of a dependency?

Related

How to force Maven to use git-describe suffix for snapshot version during install

I have third party Java project which uses Maven to build.
The project has specified 1.0-SNAPSHOT as version in pom.xml file.
...
<version>1.0-SNAPSHOT</version>
...
I'd like to build project on private build server and install resulting jar into private maven repository.
Currently when project is installed or deployed via mvn install or mvn deploy the resulting artifact has suffixed with timestamp like this artifact-name-1.0-20200320.102713-1.jar.
Such version is rather uninformative.
I'd like to have version suffix to include git describe instead of timestamp.
Is there a way to customize suffix to include more information like git commit id?
The situation is a bit different to what you probably think.
Maven has just one build in mechanism that does not treat a version number "verbatim", and this mechanism is SNAPSHOT. SNAPSHOT versions are stored in Nexus/Artifactory as time-stamped, numbered versions so that Nexus/Artifactory can always give you last version when you ask for SNAPSHOT. There is no way to alter that mechanism.
On the other hand, you can build non-Snapshot versions that depend on properties.
You can e.g. define a version 1.0.0-${revision} and set the property revision through the command line.

Dependency not found for javafx in IntellIJ

I have installed a fresh version of IntellIJ Idea (2018.1.2) and JDK 10.0.1. Maven 3.0 seems to come bundled with IntellIJ, but I have additionally downloaded and successfully installed it. In my pom file, there is a javafx dependency, and I am getting this:
Updating indices and reimporting doesn't help. What simple thing that will make it work am I too dumb to understand?
This artifact is not on maven central. (see https://search.maven.org/#search%7Cga%7C1%7Ccom.oracle%20javafx)
Maybe you have to configure a repository in your maven configuration where you can find your missing artifacts.
I think you are trying to use JavaFX as a Maven dependency. However, JavaFX is not available in a public Maven repository. JavaFX does not need to be hosted in a Maven repository as it is included as part of the underlying Java runtime.

How Can I List the Versions From a Maven Repository?

I'm trying to read out the artifact versions that are in a Maven repository in order to update my version numbers (yes, this is the best way to do this given the restrictions we have). I can see in the metadata.xml file for the repository that it's got the version information in it, but I'd like to avoid having to request that file directly. I've so far been unable to find any documentation about Maven to do this.
A Maven repo is just a directory structure. Every version in its own subdirectory below the group and artificact directories.
On JitPack, you get a plain text list of versions, for example https://jitpack.io/com/github/twogood/kronslott-sendgrid/
For oss.sonatype.org it's a directory listing, for example: https://oss.sonatype.org/content/repositories/releases/io/dropwizard/dropwizard-core/
Add the Versions Maven Plugin to your pom.xml file.
To display the dependencies with newer versions available, run the command:
mvn versions:display-dependency-updates
To rewrite your pom.xml file to use the latest release versions of the project's dependencies, run the command:
mvn versions:use-latest-releases

Eclipse showing proper dependencies, but mvn package produces WAR with out-dated dependencies

I'm working with a web app, called A, using maven, in eclipse, going between using m2e eclipse plugin and command line maven.
A depends on a custom library B, which is installed in the local repo. A details this dependency in its pom.xml
When I test the app in eclipse using eclipse's Tomcat, everything is fine -- the up-to-date version of B is used, and I see so in Maven dependencies folder.
But for some reason, when I go to command line and run mvn package, the resulting WAR uses out-dated version of B. I can tell because when I get it deployed to app server, its logging and functionality is broken in a specific way that was fixed in a newer version of B.
Is there any way for me to debug what's going on here? What is eclipse doing that mvn package is not including?
Project definition:
<groupId>org.com.web</groupId>
<artifactId>DocImgTransfer_Servlet</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
Dependency on lib that is somehow getting old version:
<dependency>
<groupId>DocImgTransfer</groupId>
<artifactId>DocImgTransfer</artifactId>
<version>1.0.0</version>
</dependency>
So really 3 questions:
If it is just some issue with maven grabbing the wrong version from local repo, is there a way for me to tell Maven to double-check the dependency version it's pulling in?
Will mvn clean or mvn package -U possibly help in this case at all?
Is the only advice to just double-check groupId, artifactId, version in pom.xml?
If it is just some issue with maven grabbing the wrong version from local repo, is there a way for me to tell Maven to double-check the dependency version it's pulling in?
a) Is your CustomatJar-1.0.0.jar version that eclipse is referring to same as maven is picking up or is maven picking up an older version?
i.e. Do you own the code for CustomatJar and are you just updating it v/s the one getting packed in war is truly an older version e.g. CustomatJar-0.0.5
i) You could tell by just unzipping the war and seeing which version is packed inside the jar.
ii) mvn dependency:dependency would tell you which dependencies maven command line thinks should be packed. more info
Is the only advice to just double-check groupId, artifactId, version in pom.xml?
Could you server have got an older version of CustomatJar in say it's lib?
You did double check your POM.xml already ... correct?

Missing artifact com.google.android:android:jar:4.4_r1

I'm trying to use Android 4.4_r1 and Maven for a project but for some reason the version maxima maven let me use is 4.1.1.4
I know it is not possible redristribucion android.jar and therefore the necessary maven-android-sdk-deployer, I've cloned the project and have run the command
mvn clean install -Pall,with-javadoc
and install all libraries, later when i edit the pom.xml file i get the following error
Missing artifact com.google.android:android:jar:4.4_r1
I've checked into the path ~/.m2/repository/com/google/android/android and i can see the following versions
1.5_r4 2.2.1 2.3.1 4.1.1.4 4.2.2_r2 4.3_r2 4.4 4.4_r1
What am I doing wrong?
From https://github.com/mosabua/maven-android-sdk-deployer -
The android.jar artifacts in Maven central are available with the
groupId com.google.android, whereas this tool uses android.android to
avoid overlap.
This means that when using the Maven Android SDK deployer your pom.xml should reference the artifact like this -
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>4.4.2_r2</version>
<scope>provided</scope>
</dependency>
Note: the 4.4_r1 is no longer shipped in the Android SDK as it has been replaced by 4.4.2_r2.
The 4.1.1.4 version was the last com.google.android:android version uploaded to Maven Central, that's why it's the latest one you can reference using com.google.android:android.

Categories

Resources