How to download JAR with classifier from Maven repository? - java

I am trying to download JAR named mygroup-myid-myversion-jar-with-dependencies.jar from maven repository and tried commands
mvn -q org.apache.maven.plugins:maven-dependency-plugin:2.1:get -DrepoUrl=MYURL -Dartifact=mygroups:myid:myversion:jar-with-dependencies
mvn -q org.apache.maven.plugins:maven-dependency-plugin:2.1:get -DrepoUrl=MYURL -Dartifact=mygroups:myid:myversion-jar-with-dependencies
And both failed with error of being unable to find artifact.
Is this addendum called "classifier"?
How to donload JAR with classifier?

Use -Dclassifier=<classifier> or -Dclassifiers=<classifiers> if you have more to download.
This worked for me:
mvn com.googlecode.maven-download-plugin:download-maven-plugin:artifact -DgroupId=org.jolokia -DartifactId=jolokia-jvm -Dversion=1.6.0 -Dclassifier=agent

This one happened to me. I have a remote repository on one of the internet sites and our internal nexus are not getting those dependencies remotely from this host. We have a security setup that only nexus server can connect from outside world and our dev machines have no access to those kinds of remote repository hosts.
All of the artifacts are fine and can be downloaded via proxy repository but some are not, specially like this artifact with dependency classifier below.
<dependency>
<groupId>com.asset</groupId>
<artifactId>integration-adapter</artifactId>
<version>1.28.76</version>
<classifier>jar-with-dependencies</classifier>
</dependency>
Here are the steps that works for our development teams.
1.) As I'm admin I can remote download those problematic artifacts.
2.) From a secured host, make this file available.
3.) Follow this link from Nexus https://support.sonatype.com/hc/en-us/articles/213465818-How-can-I-programmatically-upload-an-artifact-into-Nexus-2-
4.) This is how I build/deploy to an internal repo so clients can download during their own specific builds for their projects.
mvn deploy:deploy-file -DgroupId=com.asset -DartifactId=integration-adapter -Dversion=1.28.76 -Dclassifier=jar-with-dependencies -DgeneratePom=true -Dpackaging=jar -DrepositoryId=nexus -Durl="http://your-nexus-host:8081/nexus/content/repositories/repo-releases/" -Dfile=integration-adapter-1.28.76-jar-with-dependencies.jar -DupdateReleaseInfo=true
Doing above way creates pom files and meta data in our corporate nexus so maven clients can download those artifacts.
5.) At your .pom file please add these dependencies below:
Looks like in this remote repository (the external host) these files were uploaded directly that is why there are missing maven pom files and we as consumers/clients cannot build it as normal with other working artifacts they have.
Note : So if your are publishing artifacts to the outside world and make your artifacts downloadable make sure you know and read on step 3 above.

Related

How to include local artifacts with Maven dependency:go-offline

I'm trying to generate an offline local maven repository folder for my project, which includes both remote dependencies, and a few dependencies to local projects.
When I run mvn install in my project, Maven succeeds in resolving both remote and local dependencies. Now, in order to have all dependencies available offline, I want to have a local repository folder in my project. Using the command mvn dependency:go-offline -D"maven.repo.local"="./maven-local" I try to achieve this. However, Maven manages to place all remote dependencies in the local folder, but not the local dependencies to my local projects (which have been installed already).
The error I get is:
Failed to execute goal on project genericgateway: Could not resolve
dependencies for project org.my:ownproject:jar:1.0.1: The following
artifacts could not be resolved: org.my:otherproject:jar:1.0.1: Could
not find artifact org.my:otherproject:jar:1.0.1 in central
(https://repo.maven.apache.org/maven2)
How can I tell Maven to also search in my local ~/.m2 repository for these projects?
Basically you should work with one local repository for compilation of maven project.
So, you have three options:
Option 1
Don't specify a local repo while executing mvn dependency:go-offline. Let it download into you regular local repo (~/.m2 by default)
Install the local artifact there as well and compile against this repository.
Option 2
Compile local projects into ./maven-local with maven.repo.local flag as you did. The point is that that both local and downloaded artifacts will be in the same repo.
If you want, you can configure a local repo in the settings.xml (see this answer
Option 3
IMO Overkill for local dev env, but still...
If you absolutely have to separate the repositories you can install a software like Nexus/Artifactory locally - it can provide a flexible repository management and then configure different repositories, but then again, it will be like a remote repo residing in your local PC, maven will create a local cache with both local and remote artifacts, still in the same repo.

How to add java library without no repository to pom file?

I'd like to add one project A as my dependency, but unfortunately, there's no repository host this library. I know that I can install it to local repository manually, then refer this in pom file. But I have a travis build job where there's no such artifact, is there any way that I can install this library to local repo automatically ? Thanks
I would recommend to use the clean approach and uploading this library into your own repository. If you don't have one: time to get one running.
If you're really not up to this task the maven install plugin: http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html can install a jar in the local repository. This will work both locally and on a CI server.
To upload a jar in a remote repository there is the deploy plugin: http://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html
If you bind the execution of this plugin to a very early phase in the maven life-cycle (validate) you might be able to avoid a build step required prior of your own build.

How to configure maven without internet access

While converting dynamic web project into maven project I'm getting this error:
"CoreException: Could not calculate build plan:
Plugin org.apache.maven.plugins:maven-compiler-plugin"
I can't access the internet to download any jars and plugins while converting because I'm on a restricted network with no internet access. Is there is any way to make a Maven project with no internet access?
I'm using:
Eclipse kepler
Maven 3.0.4
JDK 1.6
You can manually download or some how find required artifacts.(jars) Then copy them into your local maven repository.
Now you can use
mvn clean install -o // off-line build
to build your project without internet.
About half year ago, when I worked as an intern in a company, we also encountered with virtually the same problem as you ------ we were in the restricted network, and our computers couldn't access the internet, but we still needed to use maven to update the project dependencies. Here is our solution:
Find a server that can access the internet, and also you can access
the server in your restricted network.
Establish a sonatype nexus server on the server you found above.
The sonatype nexus serer is just a private repository in your environment. You can upload your own packages into the repository, and also the nexus server can download required packages from the central maven repository.
The last thing you need to do is to change the repository address in your pom.xml to the nexus server address
Hopefully, this can help you. And if you have any questions, please feel free to ask me again.
mvn clean -o install
Running in Offline Mode
If you ever need to use Maven without having access to a network, you should use the following option to prevent any attempt to check for updates to plugins or dependencies over a network:
-o, --offline
When running with the offline option enabled, Maven will not attempt to connect to a remote repository to retrieve artifacts.
refer here and here for more options
I think without internet you can not download it, initially you need an internet connection because maven need bunch of dependency and it all depend on your project. if you download them manually one by one there is some chance that you could miss some dependency and error will resolve one by one it will take more time and research to search dependency over internet and fix them one by one.
so I prefer instead of downloading manually go for internet connection it will download all the dependency automatically.
if you have restricted access download it at home and replace that folder with your work area folder
Maven is a dependency management system which downloads the required dependencies from the internet or a mirror of the central maven repository. Incase you do not have both - connection to internet (Central Maven Repository) or a local mirror (Nexus is the most used replicator of the central maven repository in a Enterprise setting) - then maven is bound to get the dependencies off your local hard disk from the .m2 folder under your logged in user directory.
Hence, in order for maven to work, manually register all dependencies which you have listed in the pom(s) as described in the maven guide :
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
You can try copying your .m2 folder to the machine without internet... and then running maven offline.

Download a Maven artifact and install into a specific local repository (not .m2)

I have several local Maven repositories besides the one located in ~/.m2 directory and I want to simplify the process of installing new artifacts into them from Maven central.
So far I couldn't find a way to tell mvn dependency:get that dependency should be put into a specific local repository.
I did manage to find a way to install a given downloaded artifact using mvn install:install-file -DlocalRepositoryPath=, but I want to be able to get and put dependencies into a specific repository with as few manual steps as possible.
Before you ask why can't I just configure my project to use Maven central directly here is the answer: the project uses Gradle and I do not own its build script (i.e. I can't modify it). The project build script is written to work with several distinct repositories having the same base URI that I fortunately can change using build.properties file. So my idea is to have several local maven repositories in the same root directory and trick the build script to use them.
You can use the maven.repo.local property:
mvn dependency:get -Dmaven.repo.local=/path/to/localrepo

Travis CI not using extra Maven repository provided in pom.xml

I have a Java-based GitHub project, fitnessjiffy-spring (I'm currently focused on the "bootstrap" branch). It depends on a library built from another GitHib project, fitnessjiff-etl. I am trying to configure both of these to be built by Travis CI.
Unfortunately, Travis is not as sophisticated as Jenkins or Hudson in dealing with Maven-based Java projects. Jenkins can easily handle dependencies between projects, but the same concept doesn't seem to exist with Travis. If one project depends on another, then that other project must already be built previously... and its artifact uploaded to some Maven repo where the first project can download it later.
My "fitnessjiffy-etl" library is building and deploying just fine. I'm using Bintray for Maven repository hosting, and you can clearly see my artifacts over plain HTTP at:
http://dl.bintray.com/steve-perkins/maven/
In my "fitnessjiffy-spring" project, I am adding this Maven repo location directly in the pom.xml, so that Travis will be able to find that artifact dependency. Here is the state of my POM at the time of this writing. Note the <repositories> element at the bottom of the file.
When I build this project locally, it works just fine. I can see it downloading the Maven artifact from "http://dl.bintray.com/...". However, when I try to build on Travis CI it fails every time. I can see in the console log that Travis is still trying to download the artifact from Maven Central rather than my specified repo.
Does this make sense to anyone else? Why does Maven utilize a custom repository location in a POM file when building locally, but ignores this configuration when running on a Travis CI build?
From digging into this further, I discovered that Travis uses its own proxy for Maven Central, and has configured Maven to force ALL dependency requests through their proxy. In other words, it does not seem possible at this time to use additional Maven repos specified in the POM file of a project built on Travis.
In my case, I ended up refactoring such that project would not need the outside JAR dependency. I also switched to Drone.io, so I could manage my settings on the build server rather than having to carry a YAML file in my repository (which always struck me as a bit daft).
However, even on Drone it's still a major hassle to manage dependencies between multiple projects (extremely common with Java development). For Java, I just don't think there's currently an adequate substitute for Jenkins or Hudson, maybe running on a cheap Digital Ocean droplet or some other VPS provider instance.
In your install phase add a $HOME/.m2/settings.xml define your custom repository.
cache:
directories:
- "$HOME/.m2"
install:
- curl -o $HOME/.m2/settings.xml
https://raw.githubusercontent.com/trajano/trajano/master/src/site/resources/settings.xml
- mvn dependency:go-offline
script:
- mvn clean install site

Categories

Resources