I have a requirement where I have to work on different versions of a project. I am using maven-3.2.5 and right now I have only one local repository which I configured in my settings.xml like this
<localRepository>D:/Repo</localRepository>
and I have profile like this
<profile>
<id>RepositoryConfig</id>
<repositories>
<repository>
<id>public</id>
<url>http://bxus:8081</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<url>http://bxus:8081</url>
</pluginRepository>
</pluginRepositories>
</profile>
As I already told I have to work on different releases so I need to maintain the different code bases. I want to maintain separate local repository for each code base. One way is to create separate settings.xml for each code base but that method I don't want to adopt. I want to do this by one settings.xml file.
Please share your suggestions. I am using elipse as IDE.
You should use multiple branches to track the differences between the versions. In order to share the bulk of the code. See here an introduction to git branches.
If you are using multiple disconnected local repositories you will very likely end up in a nightmare. Because you will have to replicate the changes from one repo to another.
Using a single repo with multiple branches will allow you to share the code and maintain only the differences in their own separate branch.
If you need multiple local copies, you can clone the same repo in multiple locations but switch eac one to a different branch.
Then in each branch you are able to use a different maven configuration, if needed, like others have suggested. But the answer is to use multiple branches.
Use maven.repo.local :
1.(repo1) mvn -Dmaven.repo.local= /dir/myrepository1 -DRepositoryConfig1 clean install
2.(repo2) mvn -Dmaven.repo.local= /dir/myrepository2 -DRepositoryConfig2 clean install
And
<profile>
<id>RepositoryConfig1</id>
<repositories>
<repository>
<id>public</id>
<url>http://bxus:8081</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<url>http://bxus:8081</url>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<id>RepositoryConfig2</id>
<repositories>
<repository>
<id>public</id>
<url>http://bxus2:8081</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<url>http://bxus2:8081</url>
</pluginRepository>
</pluginRepositories>
</profile>
Related
I have a local Java intelli-J project with a pom.xml that has (2) internal repositories on artifactory. The problem is I am doing some testing, and I think one of the JARs is not on this internal repo, so I want to use the regular Maven central repo. I googled and believe, the artifact should go through the list in your pom.xml is the order its listed and try to resolve the artifact, the problem is, even when I add the Maven central repo, it seems to never attempt; only tries the internal artifactory then fails.
In my pom.xml:
<repositories>
<repository>
<id>test</id>
<name>Maven Central</name>
<layout>default</layout>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>my_repo</id>
<name>MyRepo</name>
<url>https://myinternalrepo.com</url>
</repository>
<repository>
<snapshots />
<id>MySnapShotRepo</id>
<name>MyInternalRepo</name>
<url>https://myinternalreposnapshots.com</url>
</repository>
</repositories>
am I doing something wrong here?
I removed my settings.xml and was able to control the repositories from the pom.xml file tag. It also looks like maven repo is automatically tried whether you list it or not in pom .
I'm currently changing a docker image. The docker image creates a server that allows running some experiments. To adapt its functionality for my purpose, I have to change a class that is contained in a dependency jar file. In the pom.xml file, such jar dependency is downloaded with its dependencies from a nexus repository. I presume that a possible solution is to create a repository in the nexus repository (localhost) and then upload the jar file with its dependencies, right? Anyway, I would have no idea how I can do it. Below is the code concerning it.
Could someone help me up, please?
<repositories>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.liveontologies</groupId>
<artifactId>pinpointing-experiments</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
Yeah you're on the right track. What you're asking about is called a "deploy" in maven. So to deploy your jar generally you'll need to:
Create your nexus instance
Add your new repository to your pom file
Add the maven-deploy-plugin to your pom
Make your code changes
Deploy your jar with the mvn deploy command
Two good resources for lots of details on the steps and the exact content to add to your pom.
https://www.baeldung.com/maven-deploy-nexus
https://maven.apache.org/guides/mini/guide-3rd-party-jars-remote.html
Is it possible to add remote repository jar file (https://repo.ah/lib/abc.jar) in maven pom.xml as dependency in java project. if so, can you please share example.
No, it's not possible to add a complete repository as a dependency. This doesn't make sense, because a repository can contain ten thousands of artifacts.
If your project requires artifacts which are not hosted in the standard remote repository, you can specify this via the <repositories> tag in your pom.xml .
<repositories>
<repository>
<id>vaadin-addons</id>
<url>http://maven.vaadin.com/vaadin-addons</url>
</repository>
<repository>
<id>vaadin-snapshots</id>
<url>http://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
More Informations:
Introduction to Repositories
Setting up Multiple Repositories
In the comments you mentioned that the URL is an Artifactory.
So just add the Artifactory as <repository> to your settings.xml and then you can use the jar in your application.
So my default maven settings.xml file in my ~/.m2/ folder is containing links to my work repositories. So whenever I run an install on my pom.xml's it try to fetch from the corp nexus maven repositories.
For a hobby project which I am just starting with I don't want to make use of the corp maven nexus, but to make use of the central maven repo. I don't want to replace the entire settings.xml as this would mean reloading the entire local maven repo once I switch back to my corp work.
How can I achieve this ?
Add the following as your first repository in the repositories tag in the settings.xml
<repository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>central</id>
<url>http://repo1.maven.org/maven2</url>
</repository>
You may also want to use profiles. But, that is not a requirement.
You can also add a repository on your pom
<repositories>
<repository>
<id>central</id>
<url>http://rep1.maven.org/maven2</url>
</repository>
</repositories>
In my settings.xml file I have listed repositories that I want Maven to use (see the file below). These repositories are located in the build machine and I am working this way to prevent a build fail when there's is no Internet connection in the build machine.
The problem is that Maven automatically looks for updates in the central repository (and possibly from other non-listed repositories) during the build. Is there a way to prevent this behaviour?
...
<profile>
<id>myProfile</id>
<repositories>
<repository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<updatePolicy>never</updatePolicy>
</snapshots>
<id>myRepo</id>
<url>file://${my.home}/maven/.m2/repository</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<updatePolicy>never</updatePolicy>
</snapshots>
<id>myRepo</id>
<url>file://${my.home}/maven/.m2/repository</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
</profile>
...
Note: Using the offline option (e.g. -o flag) is not an option for me. What I really want is Maven to use only the repositories that I list in my settings.xml file.
Every Maven project inherits the configuration for the central repository from the Maven Super POM. You can use Maven's mirrors feature to redirect calls to central to your preferred repository. You do this by adding some configuration to your settings.xml like this:
<settings>
...
<mirrors>
<mirror>
<id>central-proxy</id>
<mirrorOf>central</mirrorOf>
<url>http://myrepository/releases</url>
</mirror>
</mirrors>
..
</settings>
This configuration can either be put in your user settings (${user.home}/.m2/settings.xml) or global settings ({$M2_HOME}/conf/settings.xml).
Set your desired repositories as a mirror of everything else.
More details: http://maven.apache.org/guides/mini/guide-mirror-settings.html