configure maven for both personal and work use [duplicate] - maven

This question already has answers here:
Maven Mirror - how to bypass if mirror host is not available?
(3 answers)
Closed 8 years ago.
At my job we use a nexus server that requires credentials. it is also only available through our network (or VPN). I was provided with a maven settings.xml for this purpose.
I also want to have a more conventional configuration for some side projects of mine, because using the same configuration is very inconvenient, but Im not sure of how to switch configurations without replacing the whole settings.xml every time.
The settings is basically taken from this example but with a entry for credentials. How can I turn off this config and connect to the central maven repo when I'm at home?

well, you seem not to be the first one facing the problem. I've found some discussion on this here: http://maven.40175.n5.nabble.com/Conveniently-switch-between-settings-td126255.html
However I don't think there is fully flexible/automatic solution the one would expect.
As a summary of the discussion, I see 2 options:
switch the settings.xml based on your environment or
use the -s switch for mvn command to specify the alternate settings.xml file
My experience is that, switching settings.xml based on environment (the 1.st option) does the job for me.

All you need is define 2 profiles in your settings XML - one should use the intranet-only repositories, the other - open internet repositories (e.g. Bintray's JCenter).
Then define one of the profiles active by default, and trigger the usage of the other with -p (and disabling the auto-activated with !)
Here's the full profiles reference for you.

Related

Download maven2 repository for offline use

We are developing offline due to limited internet resources and would like to run once every several months a whole grab of an external repository (e.g repo1.maven.org/maven2 - Disk space isn't an issue).
Today I'm using a simple POM that contains a lot of common dependencies that we are using, I've set my local maven to use a mirror to proxy thru a local nexus repository to cache locally and this is how I'm grabbing for offline use - but that isn't very effective.
I'm now looking for a command line tool that allow me to run searches on maven repositories so that I can write a script that grab them all to my local nexus installation and would like to hear if there is any or if there is another way to achieve that.
Thanks
Not a whole solution (yet) but I'm using httrack to grab the whole content of repo1.maven.org/maven2 - That is already better than nothing :)
In general, there is a goal in Maven dependency plugin called "go-offline"
So it allows to grab all the project dependencies and to store them in local .m2 repo.
You can find more information here.
If you want to run Maven and tell it to behave like the network does not exist you can run it with "-o" option (offline mode). So that if there is no dependency installed locally, Maven won't even try to go to network and bring it - but will fail the build.
On the opposite, if you want to force Maven to check and bring new versions (otherwise they already should be in your repo), you can use "-U" option.
I'm not really sure I've got the point about general search-and-download use case. Usually people install Nexus or Artifactory once in a network so that each dependency will be downloaded only once. In local development machines people usually just work with filesystem and don't maintain tools like this.
Now if you want to copy the whole repository from internet (for copying it later to some other network or something) you can just use crawlers like Apache Nutch for example or craft your own script that will recursively download all the files.

Can I upload TeamCity definitions as XML?

TeamCity appears to store the definitions for builds, projects, templates etc as XML internally.
This is exposed in the "Administration > Audit" view where you can see diffs that people made to individual configurations, at URLs like http://teamcityserver/admin/settingsDiffView.html?id=project:project10&versionBefore=8&versionAfter=9&actionId=3151
I'd like to manage a TeamCity setup partially from outside the web interface - e.g. for example keep the build definitions in version control and perhaps programmatically generate them.
Is there any way I can directly upload definitions in this format (or any similar alternative)? I'm aware that there are various APIs and extension points to TeamCity but haven't managed to find any that gives direct access to anything like this.
I can live with the format changing with TeamCity versions if necessary - it would be a reasonable price to pay for the other benefits.
For TeamCity 9.x and newer
As reported by Ganesh in the comments to this answer, an option was added in 9.x that supports changes and versioning through Source Code Management (SCM) tools. Please see his answer for 9.x and beyond.
For TeamCity 8.x and older
It might not be the "approved" way, but you can edit the project files on disk, and those changes will appear in your build configs. I have successfully edited them outside of the Web UI after they were created.
So, you could probably open that folder up as a restricted network share or set up ssh.
You'll find it at $TeamCityData/config/projects/ and then they are stored in subfolders such as $projectName/buildTypes/$buildFile.xml
An example is:
E:\TeamCityData\config\projects\CSandbox\buildTypes\CSandbox_Project1TrunkBuildUnitTest.xml
TeamCity 9 adds a new "Versioned Settings" feature which keeps these XML files under version control and allows changes to be made via the VCS.
In TeamCity 9.0 this can be git or mercurial, and the upcoming TeamCity 9.1 will add support for Perforce and Subversion.
I've been using it with git for a few months and it works quite nicely in practice.
I sometimes have trouble persuading TeamCity to notice changes coming in from the VCS - particularly when deleting projects - but otherwise it's been really useful for standardising configuration and spinning up new job chains quickly.
Another slight annoyance is that you can't configure the location within the repository that the settings come from - it's always .teamcity in the root - so I've had to use multiple branches or repositories to manage multiple TeamCity servers.

Multiple Maven Mirrors for the same repositories

As a consultant, I have multiple clients that I'm doing work for. Each client utilizes their own internal Maven repository that is also set up to mirror Central and other external repositories. I need to configure my maven installation on my laptop so that when I'm doing work for one client, it utilizes their internal repository for everything.
I had thought I would be able to utilize profiles to handle this, but mirror settings cannot be changed per-profile.
Does anybody have suggestions on how to approach this maven configuration?
Note: A similar question is here: How do I configure maven to access maven central if nexus server is down?, but that question deals with switching between Central coming from a mirror or not. What I need is for Central (and others) to come from one mirror or a different one based on some property/setting/variable etc.
Create two shell aliases:
alias build_at_home="mvn -s $HOME/.m2/home_settings.xml"
alias build_at_work="mvn -s $HOME/.m2/work_settings.xml"
The "-s" option is handy for explicitly stating which environment settings file to use.
We use this mechanism on our shared build server to ensure each project build is isolated.
Obviously on windows you could create a set of batch files.
I have a very similar requirement in my project too. I created two separate settings.xml files, named them as settings_one.xml and settings_two.xml and saved them in the MAVEN_HOME. Depending on which file I need, I have a small script (a bat file on windows) which overwrites the existing settings.xml with one of the two settings files.
del C:\Users\<username>\.m2\settings.xml
copy C:\Users\<username>\.m2\settings_one.xml C:\Users\tadigotl\.m2\settings.xml
The simplest solution i can suggest is to install git and commit you .m2/settings.xml (of course ignore the repository itself via .gitignore) into git and make appropriate branches for the customers. Change the settings will be done by:
git checkout CUSTOMER_BRANCH
and furthermore any change is tracked by a SCM.

Is there something similar to Maven Cargo but for AppAssembler?

I want to deploy a generated Maven AppAssembler assembler/ directory to somewhere in a file system, SSH, or whatnot. Can Cargo do that for me, or is there an equivalent deployment tool that will let me glob a bunch of files (in this case the target/appassembler/ directory) and deploy them to a destination?
I have a couple command-line applications that run as scheduled tasks (via cron or Windows Scheduler), and I want to deploy them out to these remote locations (in one case via SSH, and another a network share \\servername\C$\whatever\). I don't know how I can accomplish that, since all of the deployment plugins I have been looking at cater to web applications and app containers or Remote repos like Nexus.
Try maven copy plugin - it has excellent networking support (scp,FTP,HTTP).
You might also find useful maven sshexec plugin.
I know this question is quite old, but since someone else might also be interested in this:
I don't have a complete/concrete example for this, since I never tried it, but maybe the maven assembly plugin could be used for this, with the dir assembly format?

Good Reference for Hudson/Maven/Mercurial Integration

Can anyone provide a good reference (web, book etc.) that explains how to set up Hudson to do builds/releases using Maven/Nexus and Mercurial? I would like to set up our system to do Maven builds in Hudson based on updates to our Mercurial SCM projects which are automatically deployed to our local Nexus server. Some of the project are dependent on others. I can find quite a few references that refer to one part of the equation, but haven't found anything that details all the pieces together.
TIA!!
EDIT
I think what I am looking for initially is more of a general overview of how to use these tools in an integrated manner. And then I can delve into the details. What I'm looking for is how to use Hudson to do/verify builds and based on the results, push the artifacts to the appropriate Maven/Nexus repository (snapshot or not) and also possibly deploy applications from Hudson as well to our pre-prod systems. The fact that I'm using Mercurial is incidental.
Hopefully that clarified and didn't muddy my question...
I don't know about the books, I did our integration by using Hudson help.
I think, though, that one area is totally not clear out of the box: providing your own version of settings.xml ( that's where you may set custom repository, profiles, etc )
Here are the steps:
Go to Hudson->Manage Hudson->Maven 3 Configuration
Under 'Documents' tab click 'Add'
Change 'Type' drop-down to 'SETTINGS'
Give it a meningful name ( e.g. my-custom-settings )
Cut and paste the WHOLE xml that you would usually put into $HOME/.m2/settings.xml
Hit 'Save' button at the bottom of the screen.
Now you are ready to setup Maven project
Create new job and tie it to your source control
Add 'Invoke Maven 3' build step
Click 'Advanced' button
In expanded list find 'Settings' drop down
Choose 'my-custom-settings'.
With custom settings you can provide deploy credentials, custom profiles, etc.
I really wish Hudson team would have provided similar instructions in their help for Maven build step, instead of links to 'Settings Reference' at maven.apache.org website.
As for mercurial integration, quick search returned this article -> http://www.ashlux.com/wordpress/2010/06/16/triggering-hudson-builds-with-mercurial-hooks/
I am not mercurial expert, but the article is consistent with the setup we used for our SCM integration.
I wrote a blog which talks about setting up project using Jenkins and maven, If i am right Jenkins is a spin off from Hudson. Try it out it might help
http://prasannatalakanti.blogspot.com/2011/08/continuous-integration-using-open.html

Resources