Manually downloading and installing maven plugins - java

I am on proxy network and proxy is preventing maven to connect to central repo
Is there any way to download the maven plugins manually and installing the plugins in local .m2 repo.
Thanks

If you have the jar, you can use :
mvn install:install-file -DgroupId=<your_group_name> \
-DartifactId=<your_artifact_name> \
-Dversion=<version> \
-Dfile=<path_to_your_jar_file> \
-Dpackaging=jar \
-DgeneratePom=true
An example of the same:
mvn install:install-file \
-DgroupId="org.apache.maven.plugins" \
-DartifactId="maven-site-plugin" \
-Dversion="3.7.1" \
-Dfile="D:\Jars\maven-site-plugin-3.7.1.jar" \
-Dpackaging=jar \
-DgeneratePom=true
if you don't have the (plug-in) jar, and it's not a private artefact, you can find the jar and the information in repository website (for example http://mvnrepository.com/ ) or download from your private repository like Nexus or Azure Feeds.

Have a look here if you want to configure a proxy for maven. That way you do not need to download the dependencies in any obscure and unreliable way: Howto configure a proxy for Maven

The simplest way to do this is to use any machine that can connect to central to download all repo you need then copy ./m2 manually to your machine with usage of offline flag every build
if your solution is scalable you will need to install nexus or any maven repository on machine can goes outside and you configure maven to see repo machine. and this is the model solution to that case

To install a jar you can use install:install-file to install any kind of jar. But a maven plugin comes with dependencies so you will have to install them. My suggestion would be to copy a .m2 repo from a machine with access to the internet (for maven).

Related

How to deploy private jar to gitlab Maven repository

I would like to know if it is possible to deploy a custom jar file into an existing maven repository. By custom, I mean, my own existing jar from my local machine.
So, I have a project test-project on gitlab (https://gitlab.com/group/test-project), and it is a java application that I build and deploy using gitlab pipelines. In the build stage, I am doing mvn deploy and the package test-project.jar is pushed to a gitlab maven repository (https://gitlab.com/group/test-project/-/packages).
Now, I have a dependency.jar file which is listed as a dependency in my pom.xml. I would like to push that file into the same maven repository as my test-project.jar. There is nothing about that in the documentation here. https://docs.gitlab.com/ee/user/packages/maven_repository
I tried to push it with maven-deploy-plugin in a way described here http://maven.apache.org/guides/mini/guide-3rd-party-jars-remote.html
I am getting an error Failed to deploy artifacts: Could not find artifact... which is strange because I am trying to push new artifact, of course, it does not exist.
I am not sure if this is an issue with GitLab (I doubt that) or I am doing something wrong, or what I want is just not possible.
Edit
I was able to push the package but the thing is I needed to run deploy:deploy-file from the build, not from my local.
This would be the pipeline configuration
stages:
- build
maven-repo-push:
stage: build
image: maven:3.6.2
variables:
GROUP: "com.example"
ARTIFACT: "myproject"
VERSION: "1.1.1"
REPO_PROJECT_ID: "12345678" #gitlab project ID
script:
- mvn deploy:deploy-file
-DgroupId=$GROUP
-DartifactId=$ARTIFACT
-Dversion=$VERSION
-Dpackaging=jar
-Dfile=$ARTIFACT-$VERSION.jar
-DgeneratePom=false
-DpomFile=$ARTIFACT-$VERSION.pom
-Dfiles=$ARTIFACT-$VERSION-tests.zip
-Dtypes=zip
-Dclassifiers=tests
-DrepositoryId=gitlab-maven
-Durl=https://gitlab.com/api/v4/projects/$REPO_PROJECT_ID/packages/maven
-s settings.xml
when: manual
Make sure you have pushed with this configuration the files you want to push in format $ARTIFACT-$VERSION.jar and
The default settings.xml needed for authentication
https://docs.gitlab.com/ee/user/packages/maven_repository/#authenticating-with-a-ci-job-token
Still, my question remains, is it possible to do this from local
You can publish a library/jar from local file system as well, just have a settings.xml something like
<settings>
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Private-Token</name>
<value>PUT-YOUR-PRIVATE-TOKEN-HERE</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
Or if you wan to use a group token or deploy token , make sure you update the property name above , documented here https://docs.gitlab.com/ee/user/packages/maven_repository/#authenticate-with-a-deploy-token-in-maven
And then use this to publish your jar on GitLab's package registry, keep in mind that you can only publish to project api endpoints , but you can use group endpoints to download/install artifacts locally
mvn -s settings.xml deploy:deploy-file \
-Durl=https://gitlab.com/api/v4/projects/<PUT-PROJECT-ID-HERE>/packages/maven \
-DrepositoryId=REPOSITORY-ID # has to match the settings.xml server:id \
-Dfile=your-lib.jar \
-DgroupId=your.group.id \
-DartifactId=artifact-name \
-Dversion=1.0 \
-Dpackaging=jar \
-DgeneratePom=false

exclude specific folder from library

I have a library that is incompatible with java8. It's xws-security:3.0. I can't use it fully because there's trouble in crypto/xmldsig/1.0.
On the screenshot, you can see situation in the intellij idea.
How can I solve this problem by gradle exclude?
You can download it from repository and then install it into your local repo. https://springframework.svn.sourceforge.net/svnroot/springframework/repos/repo-ext/javax/xml/crypto/xmldsig/1.0/xmldsig-1.0.jar
Code:
mvn install:install-file -Dfile=xmldsig-1.0.jar -DgroupId=javax.xml.crypto -DartifactId=xmldsig -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true

Using third party lib with maven

I'm trying to use Synthetica library with maven but I failed.
There are 2 different jar file I need to import. First one is synthetica.jar and the other one is syntheticablackeye.jar.
I tried mvn install:install-file but it didn't solve the problem.
I can use them with eclipse but currently I do not use any IDE like eclipse also I'm on linux.
Steps I have done:
(This is for synthetica.jar)
mvn install:install-file -Dfile=~/Dropbox/github/ChatAppServer/synthetica.jar -DgroupId=de.javasoft.plaf -DartifactId=synthetica -Dversion=1.0.0 -Dpackaging=jar
(This is for syntheticaBlackEye.jar)
mvn install:install-file -Dfile=~/Dropbox/github/ChatAppServer/syntheticaBlackEye.jar -DgroupId=de.javasoft.plaf -DartifactId=synthetica -Dversion=1.0.0 -Dpackaging=jar
the problem is how should I add dependency when the to jar files file structers are same?
I did these and It worked fine but when I check local mvn repos in my pc(.m2/repo/) there were no jar files. synthetica and syntheticablackeye file structers are same is this a problem? If it is what can I do?
What am I missing?
Edit: When I change artifactId and groupId maven trying to download jar files but they are in local repo?
You have not supplied any details about any errors you are getting or what command you used exactly to install the JARs, so it is hard to know what exactly is not working.
You can install 3rd party JAR files in your local Maven repository with a command like this (see also Maven's Guide to installing 3rd party JARs):
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id>
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
For example:
mvn install:install-file -Dfile=synthetica.jar -DgroupId=com.synthetica
-DartifactId=synthetica -Dversion=1.0 -Dpackaging=jar
Then you refer to it in the pom.xml of your project with the same Maven coordinates:
<dependency>
<groupId>com.synthetica</groupId>
<artifactId>synthetica</artifactId>
<version>1.0</version>
</dependency>
edit - Do not use the same groupId, artifactId and version for both JAR files, otherwise Maven cannot tell them apart.

Maven Web project with Maven java application as a dependency?

I have a simple java application - maven project in my Netbeans IDE.
After I created Maven Web Application and added first project as a dependency Netbeans shows that everything is OK, and I can use all methods as well.
But in runtime I am getting
java.lang.ClassNotFoundException: com.example.dal.factory.PersistenceDaoFactory
Is it possible to make web project depending on simple java application without creating multimodule java EE application?
Yes, but you need to install your first project locally:
mvn install:install-file \
-Dfile=<path-to-file> \
-DgroupId=<group-id> \
-DartifactId=<artifact-id> \
-Dversion=<version> \
-Dpackaging=jar
Setting up NetBeans to use a project as a dependency isn't the same thing as having a Maven artifact you can use in other Maven projects; for Maven, you need to have it in a Maven repo.

How to link local repository in the maven build process

How to point to a local repository in the maven build process. In that case I want to link directory with custom jars with the compilation and packaging.
Tried following "mvn compile -Dmaven.repo.local=E:\Test\lib" but it doesn't use located jars for the compilation.
Is there way to include repository through maven pom.xml in the way we inject dependencies?
Just install the custom jars into your local repository (usually located under C:..User.m2\repository) via maven-install-plugin:
mvn install:install-file -Dfile=your-artifact-1.0.jar \
[-DpomFile=your-pom.xml] \
[-Dsources=src.jar] \
[-Djavadoc=apidocs.jar] \
[-DgroupId=org.some.group] \
[-DartifactId=your-artifact] \
[-Dversion=1.0] \
[-Dpackaging=jar] \
[-Dclassifier=sources] \
[-DgeneratePom=true] \
[-DcreateChecksum=true]
But i would suggest to install a repository manager (like Archiva, Artifactory, Nexus) and install those artifacts there. So you need to do the manual installation work only once and not on every developing machine.
The best way to configure several repositories is via the settings.xml file and not in the pom.xml file.
Exactly pom.xml is for that purpose to maintain dependencies.. you can get more on here
What do you mean by "Local Repository"?
If you mean a local Nexus / Artifactory you can use the Maven sections in your settings.xml
http://maven.apache.org/guides/mini/guide-mirror-settings.html
If you mean the local repository cache (the .m2 dir) that should just work out-of-the-box.

Categories