private internal maven repository - maven-2

I wonder whether I can setting up a private maven repository based on my svn.
The svn can be accessed via http.
If yes, then what should I do? Just uploading the architypes is enough?

If yes, then what should I do? Just uploading the architypes is enough?
While subversion is not really made for that, yes, Maven can deploy through WebDAV so it is possible (a lot of people are actually doing this for their google-code projects).
If you want to set this up for an existing maven project (and have the created artifacts deployed to your SNV repository during the deploy phase), adapt the solution described in Hosting a Maven repository on Google Code.
If you just want to add a particular artifacts, use the deploy:deploy-file goal:
mvn deploy:deploy-file \
-DrepositoryId="internal" \
-Durl="dav:https://server/repo" \
-Dfile="some-jar.jar" \
-DgroupId="my.groupid" \
-DartifactId="my-artifactid" \
-Dversion="1.2.3" \
-Dpackaging=jar \
-DgeneratePom=true
Under GNU/Linux, you can paste this command as is; under Windows, run it on one line without the \.

The question shouldn't be can you but should you. Yes you can. No you shouldn't. Instead of using a tool designed to manage source diffs for binary storage, instead get an artifact repository manager like Nexus to manage the binaries. Repository managers have tons of features designed especially to host, share, promote, secure binaries that you don't find in a typical scm. For example an scm has no capability to appropriately deal with maven snapshots.
If you want more information about why you should use a repository manager, take a look at the documents here.

Related

Upload non java artifacts to nexus 3.1.0-04

I want to be able to upload a non java artifact to hosted nexus3 repository. For this I used the curl commands described in this link uploadToNexus, but it worked only for nexus 2. I noticed also that we can create groovy script, upload them to nexus and run them (RestApi, but I'm not sure if we can create a groovy script to upload artifacts. Is there a groovy script giving this possiblity ? I'm wondering also if there is any non maven alternative to the maven deploy plugin ?
Thanks in advance.
If it's a non Java artifact, you might look at using our RAW repository, depending on what it is. However, if you for sure want to use a Maven repository, the good news is you can :)
Assuming you have a fairly normal local setup, go with something akin to this. The big change between Repository Manager 2 and 3 is that the endpoints changed, which is why the old commands are not working for you.
curl -v -u admin:admin123 --upload-file file.jar http://localhost:8081/repository/releases/org/foo/1.0/file.jar

Maven command to install remote dependency locally

I have a base pom which defines repository locations for the nexus we are running behind our firewall and all of our projects inherit from this base pom. However the base exists in one of the repositories defined in the base, so you can see the circular reference problem. I'd like a maven install:install-file like command I can have new team members run in order to pull down and install the base project locally without having to check the project out from source control and mvn install it.
I'd like a maven install:install-file like command I can have new team members run in order to pull down and install the base project locally without having to check the project out from source control and mvn install it.
The Maven Dependency Plugin and its dependency:get goal might help here, you could do something like this:
mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
-Dartifact=groupId:artifactId:version[:packaging] \
-DrepoUrl=http://repository.mycompany.com/
But let me come back on the following:
However the base exists in one of the repositories defined in the base (...)
Unless this is really what you want (adding a repository for thing not found in central), this is usually not how people declare a Nexus repository in a corporate environment.
People usually want all requests to go though their Nexus repository and store artifacts in it. Storing all the artifacts you need yourself is the only way to be sure that you'll be able to repeat your build in 1, 5, 10 years. Sure, the maven folks are doing a great job with central but are you sure you want to rely on something not under your control? So people usually declare Nexus as a mirror of everything (check the section 4.2. Configuring Maven to Use a Single Nexus Group) in the settings.xml.
And if you don't want every user to add the required snippet in their ~/.m2/settings.xml, the best option is to distribute and use a corporate version of the Maven client and to preconfigure it as required using the conf/settings.xml file.
References
Nexus User Guide
Chapter 4. Configuring Maven to Use Nexus

It's possible to put binary files on nexus repository?

At my work all development uses Java technology, and we use Nexus to manage our Maven repositories. But for a new project, the build requires dll and exe artifacts. Is it possible to put those windows binary files into a Nexus repository? Is there some plugin to make this simpler? Is what I'm trying to do crazy?
I use Nexus to store all the binary dependencies that I download from the internet.
You can upload the files using the Nexus GUI or use the Maven command line as follows:
mvn deploy:deploy-file \
-Durl=$REPO_URL \
-DrepositoryId=$REPO_ID \
-DgroupId=org.apache.maven \
-DartifactId=maven \
-Dversion=2.2.1 \
-Dpackaging=zip \
-Dfile=maven.zip
This will generate the POM for your zip package automatically.
To retrieve dependencies, you can just navigate to the Nexus URL, or use a generic dependency manager tool like ivy:
java -jar ivy.jar -dependency org.apache.maven maven 2.2.1 -retrieve [artifact].[ext]

A simple command line to download a remote maven2 artifact to the local repository?

I have a library that I distribute using maven 2. The typical user of this library doesn't use maven to build their applications, but is likely somewhat familiar with maven and probably has it installed.
I'd like to document a "simple" one line command they can use to download my library's artifacts to their local ~/.m2/repository without requiring that they set up a pom.xml to do it.
I thought there was a way to do this, but I can't seem to find it after looking through the install:install-file and dependency plugin documentation. I tried things like:
mvn install:install-file -DrepositoryId=java.net -Durl=http://download.java.net/maven/2/ -Dfile=robo-guice-0.4-20091121.174618-1.jar -DpomFile=robo-guice-0.4-20091121.174618-1.pom -DgroupId=robo-guice -DartifactId=robo-guice -Dversion=0.4-SNAPSHOT -Dpackaging=jar
but I think I'm barking up the wrong tree since it appears that the install plugin is used to copy locally built files into the local repository, rather than download remote artifacts into the local repository.
This is the artifact I'd like to install: http://download.java.net/maven/2/robo-guice/robo-guice/0.4-SNAPSHOT/
Is this possible using maven?
Since version 2.1 of the Maven Dependency Plugin, there is a dependency:get goal for this purpose. To make sure you are using the right version of the plugin, you'll need to use the "fully qualified name":
mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
-DrepoUrl=http://download.java.net/maven/2/ \
-Dartifact=robo-guice:robo-guice:0.4-SNAPSHOT
Give them a trivial pom with these jars listed as dependencies and instructions to run:
mvn dependency:go-offline
This will pull the dependencies to the local repo.
A more direct solution is dependency:get, but it's a lot of arguments to type:
mvn dependency:get -DrepoUrl=something -Dartifact=group:artifact:version
As of version 2.4 of the Maven Dependency Plugin, you can also define a target destination for the artifact by using the -Ddest flag. It should point to a filename (not a directory) for the destination artifact. See the parameter page for additional parameters that can be used
mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get \
-DremoteRepositories=http://download.java.net/maven/2 \
-Dartifact=robo-guice:robo-guice:0.4-SNAPSHOT \
-Ddest=c:\temp\robo-guice.jar

Integrating Maven & Non-maven projects

I'm currently working on two projects simultaneously:
My main project (built with maven)
A spike of an open source project, which my main project depends on (not build with maven)
How do I set up maven to use the OSS project as a dependency with the least amount of friction, given that I'm often developing the two in tandem?
I can think of several solutions:
Mavenize the existing OSS project. This is of course the "ideal" option but often not feasible (even if you introduce the new build system in parallel of the existing one). The project has likely an existing project structure that differs from Maven's standard layout. Changing the existing layout and build script may not be desired by developers, adapting a Maven build to use a non standard layout can be painful. In both case, you're screwed.
Wrap the existing Ant build with Maven. This can be nice if you want to include the build of the OSS project in the lifecycle of your project and have both of them built in one step. You can check this answer on SO for details on how to do this.
Use Apache Ivy or Maven Ant Task in the existing build to produce and install a Maven artifact in your local repository. Use this artifact as a regular dependency in your Maven project (except that you'll have to declare its transitive dependencies manually). This is maybe the quicker and less intrusive approach if building both project separately is not a problem.
It looks like you choose option 3. I think it's a good choice for a quick win.
The solution I've used is the maven-ant tasks (http://maven.apache.org/ant-tasks/).
I added an install task onto the build.xml file, which installs the compiled .jar into the local repo.
While adding a full-fledged pom to the project would defintely be the best approach, this is a major chunk of work, and inflicts maven on the project (where the other users would prefer not to use it).
I think you probably need to bite the bullet and set up a POM for your OSS project tree. This is the painful part (as you would need to hunt down the details of specifying resources paths for various plugins involved depending on the OSS app type (i.e. web, etc.)). Good news is that this is a one time effort.
Once that is done, your main project can refer to the (wrapped) OSS project as a dependency. Here a (standard maven) multi-project structure would apply.
If OSS project has dependencies - create a POM with those dependencies (your project will use them as transitive dependencies) and install that artifact and pom in local repository. If OSS project hasn't any other dependencies is even simpler - the POM is generated automatically during installing.
For both cases use maven-install-plugin.
mvn install:install-file -Dfile=your-artifact-1.0.jar \
[-DpomFile=your-pom.xml] \
[-Dsources=src.jar] \
[-Djavadoc=apidocs.jar] \
[-DgroupId=org.some.group] \
[-DartifactId=your-artifact] \
[-Dversion=1.0] \
[-Dpackaging=jar] \
[-Dclassifier=sources] \
[-DgeneratePom=true] \
[-DcreateChecksum=true]