For the longest time I used the default site I specified in the distributionManagement section of my POM to host the latest SNAPSHOT release's site. However now that I have my first version out the door, I can't use that anymore as its holding the release site.
I've gone ahead and setup a new place to store the site SNAPSHOT release, but I can't figure out how to automate the site plugin deploying there. mvn site:deploy and even mvn site:stage-deploy simply deploys to specified release site in distributionManagement, which isn't what I want. It seems the only way is to provide the URL over command line arguments, which isn't exactly an ideal situation.
Is there any way to specify a release repository and a SNAPSHOT repository for sites?
You can setup a profile for your SNAPSHOT builds that publishes to another location. Profiles let you alter numerous pom settings including distributionManagement and repositories. You would still need a way to tell maven to use the profile. There are several options to do that, some of which are automatic, and the best way is going to be dependent on your build process.
Related
Unfortunately the maven initial build is very slow due to artifacts downloading
f.e. I've tried to download the same jar using curl - it is 3 times faster!!!
Why? And how I can speed up it? Maybe maven has some config keys related to artifacts downloading speed?
Thank you.
I know its an old question, but stumbled here from Google. I already had proxy in place, just needed to speed up with concurrent downloads. You can using mvn option:
-Dmaven.artifact.threads=30
Source:
https://maven.apache.org/guides/mini/guide-configuring-maven.html
Configuring Parallel Artifact Resolution
By default, Maven 2.1.0+ will download up to 5 artifacts (from different groups) at once. To change the size of the thread pool, start Maven using -Dmaven.artifact.threads. For example, to only download single artifacts at a time:
mvn -Dmaven.artifact.threads=1 verify
You may wish to set this option permanently, in which case you can use the MAVEN_OPTS environment variable. For example:
export MAVEN_OPTS=-Dmaven.artifact.threads=3
Use a local repository manager/mirror/proxy. All downloads will then go against this instead against the public repositories on the internet. The most popular ones are:
Archiva: http://archiva.apache.org/
Artifactory: http://www.jfrog.org/
Nexus: http://www.sonatype.org/nexus/
They are fairly easy to install and set up and provide a lot of value. Most of them have free versions as well. Just use an old development box to get started and move to a real server once you want to broaden the scope and make it available to more people.
The key point of the question was missed in the answers above:
I've tried to download the same jar using curl - it is 3 times faster!!!
This means it is a software issue, mitigation by installing a local proxy or altering the snapshot policy in the settings.xml both come with extra work and potential side effects, such as snapshot dependencies not being updated.
The issue described by the question is maven not utilizing the available bandwidth, thus being slow. This issue was identified in https://issues.apache.org/jira/browse/WAGON-537 and is resolved since maven 3.6.1, see https://maven.apache.org/docs/3.6.1/release-notes.html and https://issues.apache.org/jira/browse/MNG-6591, respectively. There is thus no need to do anything else but update to the latest maven version.
The best optimization is to avoid downloading. Have a look to your settings.xml maven configuration and check if the updatePolicy flag is set to "daily" on releases and snapshots. This should be the default but sometimes it may be set to 'always' - e.g. in repository manager configurations.
Caution: In this case (daily) you have to be cautious on snapshot changes that you might not get immediatly.
I know that this is not a direct answer to your question but the best maven download optimization I know.
You can download artifact using curl (if you think that is faster) and install it to your maven repository using following command:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
Once you install it in local repository, next time maven will pick it up from there and will not try to download again.
Additionally, if the central maven repository site is slower to you, please consider using Maven Repository Mirrors.
Guide to Mirror Settings - http://maven.apache.org/guides/mini/guide-mirror-settings.html
I am on Netbeans and don't know Maven much. Whenever I import, open some Maven project, it starts donwloading something from some central repository, sometimes huge. It downloads things in .m2\repository.cache\m2e. I have limited bandwidth and don't want this. How to stop this?
I have set Options>Java>Maven>Dependency Download Strategy to never. Also tried mvn -o install and mvn -o for offline. Not solved.
The Maven way is to get you what the project says it needs, but you have not already downloaded to your local repository.
The huge file is the list of what is actually available in Maven Central, and for some reason unknown to me it is downloaded on a regular basis. If you do it once, it should be kept for future sessions.
Maven will download all the dependency only once to the local repository and not again and again.
Weather you have limited or unlimited bandwidth you have to download it to execute your project.
Maven has a very modular architecture. That means the the thing you get when you download the Maven distribution is in reality small core functionality.
The rest is downloaded from a Maven artifact repository, like Maven Central (which is the default repo).
Note that this applies not only for dependencies (the library your project uses), but also your plugins (i.e. the stuff that compiles, packages, and otherwise builds the projects). Hence the large number of downloads.
Like the other answers said, if you don't delete your local repository it should eventually contain all the artifacts (dependencies and plugins) you need without re-downloading. The only exception are SNAPHSOT dependencies which can get re-downloaded periodically, depending what's in your POM and settings.
Ultimately, you have two possibilities:
If you have access to a higher-bandwith connection somewhere, you can build the projects while using it, and your local repo will still store the needed artifacts.
If you have several computers/configurations behind a local network, you can set up a Maven repository manager, like Nexus or Artifactory, and use it as a local mirror. Note that those still need to download the artifacts at first as well.
But there isn't much else you can do. "Maven downloading the Internet" is, unfortunately in your case, by design.
Unfortunately the maven initial build is very slow due to artifacts downloading
f.e. I've tried to download the same jar using curl - it is 3 times faster!!!
Why? And how I can speed up it? Maybe maven has some config keys related to artifacts downloading speed?
Thank you.
I know its an old question, but stumbled here from Google. I already had proxy in place, just needed to speed up with concurrent downloads. You can using mvn option:
-Dmaven.artifact.threads=30
Source:
https://maven.apache.org/guides/mini/guide-configuring-maven.html
Configuring Parallel Artifact Resolution
By default, Maven 2.1.0+ will download up to 5 artifacts (from different groups) at once. To change the size of the thread pool, start Maven using -Dmaven.artifact.threads. For example, to only download single artifacts at a time:
mvn -Dmaven.artifact.threads=1 verify
You may wish to set this option permanently, in which case you can use the MAVEN_OPTS environment variable. For example:
export MAVEN_OPTS=-Dmaven.artifact.threads=3
Use a local repository manager/mirror/proxy. All downloads will then go against this instead against the public repositories on the internet. The most popular ones are:
Archiva: http://archiva.apache.org/
Artifactory: http://www.jfrog.org/
Nexus: http://www.sonatype.org/nexus/
They are fairly easy to install and set up and provide a lot of value. Most of them have free versions as well. Just use an old development box to get started and move to a real server once you want to broaden the scope and make it available to more people.
The key point of the question was missed in the answers above:
I've tried to download the same jar using curl - it is 3 times faster!!!
This means it is a software issue, mitigation by installing a local proxy or altering the snapshot policy in the settings.xml both come with extra work and potential side effects, such as snapshot dependencies not being updated.
The issue described by the question is maven not utilizing the available bandwidth, thus being slow. This issue was identified in https://issues.apache.org/jira/browse/WAGON-537 and is resolved since maven 3.6.1, see https://maven.apache.org/docs/3.6.1/release-notes.html and https://issues.apache.org/jira/browse/MNG-6591, respectively. There is thus no need to do anything else but update to the latest maven version.
The best optimization is to avoid downloading. Have a look to your settings.xml maven configuration and check if the updatePolicy flag is set to "daily" on releases and snapshots. This should be the default but sometimes it may be set to 'always' - e.g. in repository manager configurations.
Caution: In this case (daily) you have to be cautious on snapshot changes that you might not get immediatly.
I know that this is not a direct answer to your question but the best maven download optimization I know.
You can download artifact using curl (if you think that is faster) and install it to your maven repository using following command:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
Once you install it in local repository, next time maven will pick it up from there and will not try to download again.
Additionally, if the central maven repository site is slower to you, please consider using Maven Repository Mirrors.
Guide to Mirror Settings - http://maven.apache.org/guides/mini/guide-mirror-settings.html
EDIT: Ok... so I've gathered that SVN shouldn't really be used for this... which makes sense, I suppose (why version individual files when the version should be a separate jar?).
So we should use an internal server to host a repository management tool like Nexus (etc), and access that over http to pull down and put out dependencies. We are keeping our projects in SVN now. What is the standard for deployments? Dependencies go into Maven. Projects go into SVN. Should we ignore the dist and build folders? Where would our WAR files get deployed from?
OLD QUESTION (for posterity)
I'm brand new to Maven and don't know jack about it. I'm trying to evaluate it to see how it will do with our Java development.
I would like to have a Maven repository in our SVN server so that dependencies can be pulled down from there using NetBeans 6.7. I have not been able to find how to do this throughout many google and stackoverflow searches.
What are the best practices here? I'm thinking that we'd want to download dependencies using svn+ssh, but most things online seem to point to using http.
Fill my brain with great things!
I'd strongly recommend against doing this. Maven artifacts don't belong on an SCM server. You should consider using a repository manager like Nexus to store your artifacts. See here for a comparison of the main repository managers.
Having said that. If you are determined to use Subversion to host your artifacts. See this question on using the wagon scm to deploy to a Subversion repository.
If you want to find out more about Maven, check out Maven: the definitive guide.
There is a Maven plugin for Netbeans that will manage dependencies. This article lists some best practices for Maven and Netbeans.
Update based on your updated question. What to do with your own jars:
Maven has a deploy phase that will publish your artifacts to the remote repository. You need to configure the distributionManagement section of the pom, and provide appropriate credentials in your settings.xml to allow the deployment to happen. Typically you would set up a discrete logical repository on the server for your own artifacts to keep them isolated from third party artifacts. The Nexus book gives some good guidance on configuring repositories on Nexus. In particular see the Adopting a Repository Manager section.
If you have configured your project correctly, run mvn deploy and all phases up to and including the deploy phase will run, and your artifact will be published to the repository, available for use by the rest of your team/company.
If you need to restrict access to repositories, you can configure access controls to your repository so only authenticated users can access those artifacts (for Nexus see the Managing Security section of the book for guidance).
It's worth noting you can do largely the same things (more or less) with Artifactory or Archiva as Nexus, I've included Nexus references because I prefer it, and the documentation is really good.
Don't store them in SVN.
I would do two things to make sure you're not getting too many headaches:
Mirror a repository closer to your box someplace that you and your workmates can share. This will eliminate extra downloading and allow you to fix any problems that may come up (and they will) with the mirrored pom/jar files so your mates don't have to share in the headache. There are several repo managers out there that help with this.
Do your best to work with your machine repository and push changes/modifications to any pom files that you may make to the local shared repo.
Is there any way to force Maven to use remote artifacts and not those installed on your machine? since I worry about runtime errors and not compilation errors build server is not valid option.
P.S. I know I could delete or rename the .m2 folder, but I bet there is some more clever way of doing this. Maybe some plugin or special command param?
Having no local repository would mean your classpath consisting almost entirely of URLs on remote servers. I can't see why this would be supported as execution would be awful, and any dropped connection would result in classloader issues. Having a local repository ensures the jars are available before compilation/execution begins.
Also consider that WAR and EAR projects (and many using the dependency plugin) rely on downloading the jars to complete their packaging. There would be a huge overhead if these had to be retrieved from a remote repository on every build. I'm pretty sure the managers of central would not be keen on dealing with that load.
Some alternatives for you to consider:
If you want to force a clean local repository on each build, you can use the purge goal of the dependency plugin.
If you want to keep builds isolated, you can use separate Maven settings by passing -Dorg.apache.maven.global-settings=/path/to/global/settings.xml
Alternatively you can override the local repository on a per build basis by passing -Dmaven.repo.local=/some/repo/path
If you want to avoid hitting remote repositories on each build, add <updatePolicy>never</updatePolicy> to your remote repository configurations. This means Maven will only check for updates if you force it to with a "-U" switch on the command line
If you want to take the latest version of a dependency, you can use the LATEST keyword in the version declaration (instead of the version number), though this can be risky if the dependency is incompatible.
If you want to take the current release version of a dependency, you can use the RELEASE keyword in the version declaration (instead of the version number). This is like LATEST, but tends to be the newest stable build, rather than the newest.
If you want to take the latest version of a dependency within a range, use Maven's version range notation, for example [1.0.0,2.0.0) means any version from 1.0.0 inclusive to 2.0.0 exclusive
For more details on LATEST and RELEASE, see section 9.3.1.3 of the Maven book.
If you use an internal repository manager (obligatory Nexus and Artifactory references here), the overhead of purging the local repository is greatly reduced - you'll just have an increased local network traffic load.
I don't think there's really a way to do what you are asking for. You could look into depending on SNAPSHOT releases (but that means changing your version string of the upstream projects to be SNAPSHOT versions).
Incidentally, this was discussed at length in a recent Java Posse episode (#268). I don't think they ended up with a solution, but you may get some good ideas there.
I also like some of Rich Seller's ideas, which I'll be looking into myself.