Is there any way to avoid developers download all dependencies and have those dependencies located to shared locattion to all the developer and each developer working on project point to that location?
Can anyone explain with sample files and example?
Best is to go with one of the repository managers for maven. The main steps for the setup will be:
- Install a central repository on an internal machine
- Configure the central repository to proxy the repositories you need for your developers
- Modify the developers maven settings to use the internal maven repository as mirror for everything (see here for details)
There are 3 well-known repository managers available:
Artifactory: http://www.jfrog.com/home/v_artifactory_opensource_overview
Apache archiva: http://archiva.apache.org/index.cgi
Sonatype Nexus: http://www.sonatype.org/nexus/
I favorite Artifactory - the installation and configuration took less than an hour. Now if a developer adds a new dependency to a maven project, the artifact will be downloaded from the original remote repository to the internal repository and will be made available. When the next developer needs the archive it will be downloaded from the internal repository - the access will be much faster.
You can change local repository like this:
The location of your local repository can be changed in your user configuration. The default value is ${user.home}/.m2/repository/.
<settings>
...
<localRepository>/path/to/local/repo/</localRepository>
...
</settings>
look this article
I think if you make shared folder and all other developers write path to this folder this can help.(but I didn't try this)
UPDATE
Using shared repo is bad idea. Sharing local repository between two or many users is not thread safe and may result in different errors.
So as many people mentioned here use Artifactory
I think you are looking for http://www.jfrog.com/home/v_artifactory_opensource_overview
Artifactory has nice user-guide and easy to understand. I have not much experienced it but it is really powerful.
I understand what you want but i sure you that this is not a good idea. Because later conflit will happen as soon as 2 developer start working at once on same project
Maven is resolving and updating dependencies. You´ll always have a local instance of your repo somewhere. You can configure the local repository and other profiles in the settings.xml in your .m2 folder.
For example the local repo looks like
<localRepository>C:/dev/.m2/repository</localRepository>
It probably also resolves shared filesystems.
You can also add an internal repository for your own maven artifacts on a fileshare as
<repository>
<id>internal.releases.upload</id>
<name>Internal repo</name>
<url>file:////data/repo</url>
</repository>
for example. Read more about repositories here http://maven.apache.org/guides/introduction/introduction-to-repositories.html
Related
I am using Nexus and have configured maven-proxy and maven-hosted repositories, added them to a group repo and using that repo through settings.xml. Now when a new dependency is added in pom, maven-proxy goes to maven central and downloads it. However, I do not want this.
My goal is to stop replying on Maven central completely, but I know it won't work until my hosted repository contains everything that maven needs.
Issue is that Maven plugins like compiler, clean, jar etc. downloads tons of dependencies on its own. If I remove connection to maven proxy, how do I get all that list and then how do I make sure that I put whatever is needed in my hosted repository ?
Should I even try to put such artifacts in my hosted repo ? Is there any other better approach ?
You cannot really do that manually, the number of artifacts is way too large.
You can let Maven download all needed artifacts, then copy that from a remote to a hosted repository and work with that (until you need something new).
But it is still painful. I would not do that.
If your concern is security, I would use an open source security scanner instead of blocking internet access altogether.
I want to use this jar in a Maven project.
https://github.com/downloads/2checkout/2checkout-java/twocheckout-java-latest.jar
I know that the proper way is to add this jar into my local repository but I can't do this into every development machine. Is there any Maven plugin that can download this jar file and add it into my project?
There are only 3 options in a case like this:
Convince the people of the project to put their releases in Maven Central. See Guide to uploading artifacts to the Central Repository for more information on that.
Install a Maven proxy (e.g. Sonatype Nexus, see http://www.sonatype.org/nexus/) and upload the artifact manually. Each developer on the project can point to that proxy and will get the artifact.
Use the maven-install plugin to have each developer install the jar on his own local repository.
You can add below dependency into your pom.xml
<dependency>
<groupId>com.twocheckout</groupId>
<artifactId>twocheckout-java</artifactId>
<version>0.1.0</version>
</dependency>
The usual way to deal with this sort of situation is to use a shared repository such as nexus or artifactory. You configure the nexus repository to serve the locally-uploaded artifacts and you configure your pom to point to your nexus repository as one of the repositories where the artifact may be found. Then, you install the problematic artifact to the nexus repository (rather than every developer's local repository).
If desired, you can also configure your nexus to be a proxy for Maven Central (and all other repositories that you use) and have your pom configured to look only there. This results in a cache of all the artifacts that you use being held locally, which can improve performance and availability for your team (if they are co-located). This can be especially important if you have a dependency on a SNAPSHOT version that is stored in a remote repository.
The best way is to have a proxy repository installed in your corporate LAN and deploy these kind of jars in to "hosted" repositories. Then editing your settings.xml to have this as your repository.
The choice of local proxy varies from using a NAS based shared drive to using repository managers like 'Nexus' or 'Artefactory'.
This way you can easily distribute the artefacts across developers and all other users.
Simple console maven artifacts with shared dependencies (some also provide public API's in addition to their own class) living on same production server. How to best organise/install on production server?
My instinct is for a single folder holding all (version numbered) jars (ie. a 'flattened'/dependency populated 'repository') however:
(a) Can't see how such a folder would increase, on a 'dependency' basis, it's population from maven deployment repository
(b) How a jar's manifest's classpath would change from the default 'lib/...,lib/...' (ie. relative to 'main' jar, sensible for dev/test using Eclipse) to just '...,...'
What is recommended best practice as regards organisation on production server?
Google'ing 'maven production classpath' (amongst others) resulted in http://blog.armstrongconsulting.com/?p=232 which seems related but light on detail.
Any pointers?
How experienced are you with Maven? If you are the process described in the blog you mention is pretty straightforward also without going into details.
Re (a): Dependencies are downloaded from a remote Maven repository into a local Maven repository on demand. Default in ${user.home}/.m2/repository or according to <localRepository> at the beginning of your settings.xml. See Introduction to Repositories. So, there's no need for a single 'flattened'/dependency populated 'repository' folder.
A local repository can also be populated with the install:install-file goal manually. But this can be a cumbersome process if there are many artifacts to install.
See Maven, Available Plugins for what the mentioned plugin:goals do.
I'm trying to build the project from this site http://www.joptimizer.com/usage.html. I downloaded the sources jar file, unpacked it and ran maven package in the root folder. Maven fails at the last minute saying it couldn't resolve the dependency..
could not find artifact seventytwomiles:architecture-rules:jar:3.0.0-M1 in central repo - repo.maven.apache.org/maven2 ..
I have a feeling I might need to change something in the pom.xml file for this to work, but have no idea what. Googling for this missing dependency lead me no where. In general, how would one know what to do to handle such errors (and also please help with this specific case).
Specifically
According to the Building notes on http://www.joptimizer.com/usage.html:
JOptimizer is build on maven 3.0. Before building it, you must resolve
(in pom.xml) the external dependency on Colt and other dependencies
that aren't in public repositories. Please refer to the "Dependencies"
report for a complete treatment. For ease of use a boundle with
these external libraries is provided (visit "Download"): extract the
boundle in a folder and run the "maven-install.cmd" (translate it in
your own shell language), and you will get the artifacts in your local
repository.
To get the bundle for this, go to http://sourceforge.net/projects/cvxopt/files/, and download the appropriate version of joptimizer-3.X.X-dependencies.zip. Unzip in your own folder, and run mvn install:install-file -DgroupId=seventytwomiles -DartifactId=architecture-rules -Dversion=3.0.0-M1 -Dpackaging=jar -Dfile=architecture-rules-3.0.0-M1.jar -DpomFile=architecture-rules-3.0.0-M1.pom
Generally
Use a tool like http://mavenrepository.com to search for another version of the missing dependency and update your POM with the proper version. If MVNRepository doesn't know about it, you can install the dependency yourself. If you are working with a group of developers, as Eric Jablow mentions, an artifact repository like Nexus or Artifactory is great for sharing non-public dependencies. If it's just you, you can install the artifact in your local repo as described here: How to manually install an artifact in Maven 2?
You should add your own repository manager like Nexus or Artifactory. Then, find out where this dependency is kept; there are repositories other than central. If it's kept on another repository, have your repository mirror that too.
Otherwise, Nexus or Artifactory have commands to enter the dependency manually. Create a local repository called "Third-party" and add it there.
Finally, change your settings.xml file to refer everything to your repository manager.
The most common case for this is when a company refuses to license their products to be held at the central repository. For example, Microsoft won't let its sqljdbc.jar file be distributed through Central. So, you need to add it by hand.
Change the dependency as follows
<dependency>
<groupId>org.architecturerules</groupId>
<artifactId>architecture-rules</artifactId>
<version>3.0.0-rc1</version>
<scope>test</scope>
</dependency>
Add the repository in pom
<repositories>
<repository>
<id>architecturerules.googlecode.com</id>
<url>http://architecturerules.googlecode.com/svn/maven2/</url>
</repository>
</repositories>
I am working in a private network which doesn't have internet proxy.
I can not create a local repository as well which involves the bureaucracy, management won't allow it. I may be a long term fix but not the solution for the question I asked.
I can not keep maven as a build tool as it requires the direct or indirect internet connection.
I HAVE to use ANT for building the project hence using maven in offline mode also not an option for me.
But I still want to use the maven dependency management for collecting all the jars in a one archive smartly.
My plan is to generate a ZIP file containing dependencies resolved using maven. And then we will share this ZIP file to all developers working inside a private network which doesn't have internet connection.
To do so I will get a temporary access to a computer which is having internet connection and from there I will define a dummy POM with all the dependencies required.
Now the question is how do I generate a ZIP file ( not a single jar ) using maven which contains all the dependencies defined in POM.
while what youre suggesting is technically possible, it is (in my opinion) not the best solution to your problem.
your statement that
it requires the direct or indirect internet connection
is not accurate. what maven requires is a maven repository (or a set of them) to fetch stuff from. the best solution to your problem would be to install a local maven repository inside your organization's network. the 2 most popular choices for a loaclly-run maven repository seem to be nexus and artifactory - both offer free open source versions and paid supported pro versions.
once you set up a maven repository inside your organization's network and populate it with the artifacts you require you can simply configure all of your project's pom files to go to those repositories. for example, to configure maven to use your repo instead of maven central, you can do this:
<repositories>
<!-- override central -->
<repository>
<id>central</id>
<url>http://your.repo.location</url>
</repository>
</repositories>
you will need to map a plugin repository in a similar fashion.
its also possible to achieve this by configuring the maven settings.xml file in each user's home directory if you dont want this in the pom files but from my experience its less error-prone this way
use following command to build Maven project offline.
mvn -o package
Refer this and this for more information.
I ended up with a smart hack which lets me do dependency resolution and archiving!
I am creating a dummy maven web project with all the dependencies defined in pom xml.
Now the war packaging mode is used by default for web applications.
I simply install the maven project from internet facing machine.
I get all the dependencies and transitive dependencies in war file's "lib" directory with dependency naming version remaining unchanged !!!!
Copying and adding those files into an ANT project is a trivial task then..!