How to create a Maven "Project Repo" - maven

I've been asked to look at an old project that requires Maven 2.1 and a couple JARs that are not (and will not) stored in our Nexus.
I'm trying to follow the advice from #Nikita Volkov in this post about creating a project repo to hold the JARs as artifacts. The idea being I can check this repo into source control. I can then check it out on any machine and have it build without any special configuration.
To start with I've created a repo and added my first Jar to it by running:
mvn install:install-file -DlocalRepositoryPath=repo -DcreateChecksum=true -Dpackaging=jar -Dfile=lib/myJar.jar -DgroupId=my.group -DartifactId=myArtifact -Dversion=0.0.1
I then create POM that looks like:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>my.group</groupId>
<artifactId>MyApp</artifactId>
<packaging>ear</packaging>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>my-repo</id>
<url>file://${project.basedir}/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>my.group</groupId>
<artifactId>myArtifact</artifactId>
<version>0.0.1</version>
</dependency>
</dependencies>
<build>
</build>
</project>
When I view this in Eclipse if flags the dependency with error
Missing artifact my.group:myArtifact:jar:0.0.1.
When I run it from the command line Iget the error
Unable to find resource 'my.group:myArtifact:pom:0.0.1' in repository my-repo
Clearly I've not understood something in the original post, but I don't see what
So, can anybody provide a working example of how to create a in-project Maven Repo?
Update
The files stored in my local repo are:
my/group/myArtifact/0.0.1/myArtifact-0.0.1.jar
my/group/myArtifact/0.0.1/myArtifact-0.0.1.jar.md5
my/group/myArtifact/0.0.1/myArtifact-0.0.1.jar.sha1
my/group/myArtifact/0.0.1/myArtifact-0.0.1.pom
my/group/myArtifact/0.0.1/myArtifact-0.0.1.pom.md5
my/group/myArtifact/0.0.1/myArtifact-0.0.1.pom.sha1
my/group/myArtifact/maven-metadata-local.xml
my/group/myArtifact/maven-metadata-local.xml.md5
my/group/myArtifact/maven-metadata-local.xml.sha1
Update
The contents of my .m2/settings file is:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.152.78:5000/nexus/content/groups/public/</url>
</mirror>
</mirrors>
</settings>

Working solution after several updates to the original question
Your settings.xml file declares a catch-all mirror. This takes effect over the local repository declaration in your pom file. Either remove the catch-all mirror, or try excluding the repository ID of your project repository from the mirroring:
<mirror>*,!my-repo</mirror>
Original answer
Looks like you install the library to the default local Maven repository location (~/.m2/repository), but then you try to pick it up from a location within your project.
Try changing the repository location for Maven before you run the "mvn install:install-file" goal. You can do this by adding a "localRepository" setting in your settings.xml.
You could also create a new settings.xml specifically for your project and tell Maven to use that whenever you work on your project (-s parameter on the command line). IDEs like Eclipse or IntelliJ also support using an alternative settings.xml file.

Related

Repository mirroring

I'm starting with maven and is not all clear what to put in mirror <mirrorOf></mirrorOf> tag.
What I understood:
1> * means "everything"
2> ! prepended to a name exclude that name from look-up path
3> central is used whan mirroring maven central
Now what I want to do is to mirror a repository that is not maven central (teamdev's one in my case), hence I have no idea towards what the field should match: com.teamdev, jxbrowser or com.teamdev.jxbrowser
this is what is listed on temadev website as maven repo:
<repository>
<id>com.teamdev</id>
<url>https://europe-maven.pkg.dev/jxbrowser/releases</url>
</repository>
and
<dependency>
<groupId>com.teamdev.jxbrowser</groupId>
<artifactId>jxbrowser-cross-platform</artifactId>
<version>7.21.2</version>
<type>pom</type>
</dependency>
Each artifact stored in some maven remote repository, and to have it as dependency we should include this repository definition to the project pom.xml.
Most artifacts available in Central repository and it's defined per each pom.xml by super-pom.
com.teamdev
On this page
temadev website mentioned, that in order to use this dependency:
<dependency>
<groupId>com.teamdev.jxbrowser</groupId>
<artifactId>jxbrowser-cross-platform</artifactId>
<version>7.21.2</version>
<type>pom</type>
</dependency>
you have to add
<repository>
<id>com.teamdev</id>
<url>https://europe-maven.pkg.dev/jxbrowser/releases</url>
</repository>
to your pom.xml <repositories>...</repositories>.
Adding a mirror
And if you want to specify another location (artifacts download url) for com.teamdev repository-id, you may specify it in your pom.xml without mirroring.
But if your dependency contains some <repository> and downloads transitive dependencies from it, you have to add a mirror to specify another url.
in your settings.xml file add:
<settings>
...
<mirrors>
<mirror>
<id>com.teamdev-mirror</id>
<name>com.teamdev Mirror Repository</name>
<url>https://your-repository-url</url>
<mirrorOf>com.teamdev</mirrorOf>
</mirror>
</mirrors>
...
</settings>
is not all clear what to put in mirror tag
<mirrorOf>com.teamdev</mirrorOf> matches the <id>com.teamdev</id> in repository definition.
And this artifact jxbrowser-cross-platform should be available in your https://your-repository-url mirror with all other dependencies from the original repository.
And you have to refer your settings.xml file when run maven commands, e.g. if settings.xml present in the project root:
mvn clean compile -s settings.xml
or see more about settings reference here.

mvn clean install throwing build failure error

I am new to maven. I recently cloned a repository from GIT and saved it in a location on my machine. I have git bash, i am cd'ing to the location where i saved my code and trying to execute the mvn clean install command. but i am seeing the below error. It is unable to locate POM files. How can I solve this problem?. I have tried deleting the code and cloning again but that has not helped.
Below is the POM 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.XXXX</groupId>
<artifactId>XXX-XXX</artifactId>
<version>sprint1506-SNAPSHOT</version>
<packaging>pom</packaging>
<name>XXX-XXX</name>
<url>http://maven.apache.org</url>
<description>
This is the Mega pom to combine XXX, XXX
and XXX projects in a single reactor.
</description>
<modules>
<module>wesp</module>
<module>transite</module>
<module>sassy</module>
</modules>
</project>
Solution 1 : Build it by your own
As OhadR said, your local repository does not contain the jasmine-maven-plugin, so :
Clone the jasmine-maven-plugin repo (git clone git#github.com:searls/jasmine-maven-plugin.git)
Build this plugin with mvn installcommand
Build the project you cloned with mvn install command
Solution 2
If you don't want to rely on your own build, try to add the Sonatype repository to your pom, as an external source. Looking at the plugin jasmine-maven-plugin's pom, it appears that they deploy it on OSS repo.
<project ...>
<repositories>
<repository>
<id>OSS</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>
</project>
The problem was fixed when i updated the settings.xml file in apache-maven-3.3.3\conf folder. I had to configure my login credentials in the settings.xml file for the build to complete. I also had to point my .m2/repository directory to the <localRepository> tag inside the settings.xml file for the build to commence. Thanks everyone for the inputs.
Below are the fields which I changed inside the settings.xml file ( highlighted in bold):
****<localRepository>C:\Users\XXX\.m2\repository</localRepository>****
<proxies>
<proxy>
<id>XXXX</id>
<active>true</active>
<protocol>http</protocol>
<host>proxy.kdc.XXXXX.com</host>
<port>8099</port>
**<username>XXX</username>**
**<password>XXXX</password>**
<nonProxyHosts>*.XXXXX.com</nonProxyHosts>
</proxy>
</proxies>

Plugin is not being found after I install it in local repo

I have written a plugin and to install it in the local repository I run the command :
mvn install
The plugin is successfully added to my local maven repository but when I run :
com.tools:generate:0.0.1-SNAPSHOT:generatepom
I receive the error :
plugin com.tools:generate:0.0.1-SNAPSHOT or one of its dependencies
could not be resolved: Failed to read artifact descriptor for
com.tools:generate:jar:0.0.1-SNAPSHOT: Failure to find
com.tools:generate:pom:0.0.1-SNAPSHOT in
https://nexus.mydomain.com:8181/prod/content/groups/level0/ was cached
in the local repository, resolution will not be reattempted until the
update interval of nexuspro-level0 has elapsed or updates are forced
-> [Help 1]
It seems to be searching for the plugin on Nexus even though the plugin is installed locally. How can I configure maven to run the plugin in the local repository ?
Here is the build & beginning of pom.xml :
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tools</groupId>
<artifactId>generate</artifactId>
<packaging>maven-plugin</packaging>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>com.tools</groupId>
<artifactId>generate</artifactId>
<version>0.0.1-SNAPSHOT</version>
<configuration>
<repositoryUri>http://repository.sonatype.org/service/local/lucene/search?sha1=</repositoryUri>
</configuration>
</plugin>
</plugins>
</build>
most likely your plugin's pom contains different identification (groupId,artifactId,version).
Also, make sure that you specified maven-plugin there.
If it is not the case, please provide plugin's pom excerpt, or its build log excerpt (the "istalling ..." part).
You can read about developing plugins here.
I would suggest to turn your approach around and deploy the plugin to the remote repository.
If that is not desired it should however work fine. You might be running into a problem with your Maven repository meta data. I would try to run
mvn -U com.tools:generate:0.0.1-SNAPSHOT:generatepom
forcing an update as a next step.

Maven unable to download from remote repository

I'm trying to build a Maven module that depends on SVNKit.
So my pom.xml looks like this:
<dependencies>
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
<version>1.3.7</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>tmatesoft-releases</id>
<url>http://maven.tmatesoft.com/content/repositories/releases/</url>
</repository>
</repositories>
When I try to do a mvn clean install, it looks like it attemps to look into a Nexus repository, and obviously cannot find it. I'm obviously trying to download the artifact from a remote repository at: http://maven.tmatesoft.com/content/repositories/releases
I took a look at my settings.xml file in my ~/.m2/ folder and I see that there is a mirror that looks like this:
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://Our_Nexus_Repository</url>
</mirror>
I thought that, if you define a <reposotiry> tag, your module's pom.xml will take precedence over what's defined in your settings.xml file.
Any help is appreciated. Thank you.
this is because the mirror will mirror all the repositories, : <mirrorOf>*</mirrorOf>
you can change replace it like this : <mirrorOf>*,!tmatesoft-releases</mirrorOf>
more info please visit : http://maven.apache.org/guides/mini/guide-mirror-settings.html
With the way that you're using the mirror statement in your settings.xml, you're directing maven to always go to your repository. If that is indeed the behavior that you wish, you should create a proxy for the tmatesoft-releases repository inside your nexus installation.
A common methodology for doing this is to setup a repository group for all releases you wish to have on your nexus installation. Then just add proxy repos to the group as needed, and users won't need to change their settings.xml to instantly have visibility to the new repos you add.

Maven Systempath not working as expected

I have specified following dependencies(For example mentioned one here) in pom.xml which will look for saaj.jar under the specified sytempath and Maven used to pick it from same path and working fine.
<dependency>
<groupId>saaj</groupId>
<artifactId>saaj</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/webapp/WEB-INF/lib/saaj.jar</systemPath>
</dependency>
Now I have moved to windows 7 and Spring Tool suite 2.7.1 version(Previously Win XP and Spring older vesion). In this new setup am getting below error.
Missing artifact saaj:saaj:jar:1.0:system
Now, It is looking for saaj-1.0.jar instead of saaj.jar and under the folder ${basedir}/src/main/webapp/WEB-INF/lib/saaj/saaj/1.0/ instead of ${basedir}/src/main/webapp/WEB-INF/lib/.
Why is it so? Please provide the solution where my previous setup should work fine.
Avoid systemPath, you must create a local repository like :
this is you pom file :
<repositories>
<repository>
<id>local-repo</id>
<url>file://${basedir}/lib</url>
</repository>
</repositories>
<dependency>
<groupId>tiago.medici</groupId>
<artifactId>eureka</artifactId>
<version>0.0.1</version>
</dependency>
on project you create a lib folder to put your jar and maven pom file generated from
mvn install:install-file -Dfile=c:\tiago.medici-0.0.1.jar -DgroupId=tiago.medici -DartifactId=eureka -Dversion=0.0.1 -Dpackaging=jar
tiago.medici-0.0.1.pom
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>tiago.medici</groupId>
<artifactId>eureka</artifactId>
<version>0.0.1</version>
<description>POM was created from install:install-file</description>
</project>
Don't use system scope. It was meant for system provided libraries. Given the path you gave for it, you are obviously creating a web application.
Use a war project and specify your dependencies with provided scope if they're already available (e.g. because they are provided by your application server) or without a scope specification otherwise. Maven will take care of packaging your project dependency in a correct way, both for Eclipse development and for deployment in your application server.

Resources