Maven / OSGi: deploying to an OBR which is not the maven repos - maven

My maven build installs artifacts locally and requires access to the project's remote maven repository. I don't have write access to that repository - so my builds (containing my changes) are only local so far.
When I build, I would like to deploy the .jar to a remote OBR which I have control over. This is not a full maven repository (eg. Nexus), just a webserver. A repository.xml describing the OBR should be automatically generated and uploaded.
Simply calling the goal "deploy" will try to upload to the project's maven repo, which fails as I don't have write access.
I want:
build & install locally, getting all dependencies on remote maven repos as required
upload jars to the OBR
generate repository.xml OBR description and upload
How should I configure the maven-bundle-plugin? Which goal must I call?

Related

How to download selective dependencies using Maven from JFrog Artifactory?

I have a simple Maven project and its pom.xml has some dependencies to some local jar files inside the project structure. Now I want to upload those local jar files in JFrog Artifactory and change the pom in such a way so as to use selective dependencies from Artifactory and rest of the Pom files remains the same like it was(which includes some spring boot, Junit, surefire dependencies etc etc). How can I alter the pom file so that I can selectively download those jars from Artifactory rather than from my local machine.
I uploaded the local jars in a folder in Artifactory but unable to configure my pom/maven to download those during clean install. I tried as per the documentation in Jfrog to modify the settings.xml and include the server tag and aslo added distribution management in pom.xl to refer to the Jfrog Artifactory. But this is for all the dependencies no? I want selective dependencies to be downloaded from Artifactory.

Maven pom to zip config files from GitHub and jars from artifactory

Requirement:
Need to push config files and jars from artifactory to UCD for deployment.
Config files are present in GitHub repostiory.
Jars (not needed for build but needed to start application in UCD) are present in artifactory.
What would be the general process to follow, in order to copy config files from github and download/copy jars from artifactory and package everything in a zip file to push to UCD?
You might consider:
the maven download plugin to get the files you need from an URL (like a GitHub repository or an Artifactory one)
the maven assembly plugin to build your archive
configuring on UCD side the source of your Nexus package to deploy, although there is a urbancode plugin maven-ibmucd which could be handy (not tested)

Backup Maven dependencies to repository

I am frequently using maven artifacts as dependencies from external repositories which go (permanently) offline surprisingly often. I'd like to save all dependencies a given project has and save them in a local repository - just like using maven deploy -DaltDeploymentRepository=... for a single project. This repository should then be usable like any other maven repo when put on an HTTP server.
I tried using mvn dependency:copy-dependencies -Dmdep.useRepositoryLayout=true, but it does not create files like maven-metadata.xml or copy .pom files.
I do not want to use any repository managers like Artifactory, I just have a static file server.
Thanks in advance.

Maven install local usage when using a repository manger

I am lacking some basic understanding of using a repository manager for our projects. What I don't know is how, if I use a repository manager, if I run a local install command Maven doesn't deploy the package to something like a shared Nexus instance. I seem to have some confusion between local repositories and shared ones when using a repository manager.
Apologies for the naivity and for not testing this myself. We have started versioning our application and using a shared file system approach to getting artifacts and are left with a few questions about what, within the scope of what we are currently doing, will be gained by using a repository manager instead. We do use TeamCity as a build server which is deploying to that currently used file system. I need to know some answers to a few questions before POCing a repo manager.
install is specific to the local repository.
From Maven's point of view whether a remote repository is hosted by your repository manager or is completely external has no relevance - when you're adding your artifact to any kind of remote repository, you need to use the deploy plugin (or release for non-trivial deployments).
Repository managers usually generate instructions on configuring your projects for deployment to a hosted repo.
maven defines a lifecycle (clean, compile, install, deploy...). There are default mappings when you execute "mvn install". So maven knows which plugins to execute for that maven goal.
The Introduction page gives a good overview what happens for each phase (goal) and what the default plugins are: https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
In your case: mvn install will copy the artifacts into the local maven repository to be shared by other projects you have locally.
If you want to share artifacts with other developers on other locations "mvn deploy" will copy the artifacts to the remote repository. Note you need to configure the distributionManagement section in the pom.xml to be able to do that.
The normal maven setup should look like this:
project -> local repository -> private remote repository -> public remote repository
Project: in the simplest case your project consists of source files and a configuration file (pom.xml). The project may depend on third party libraries like junit. The jar files of the libraries are not stored in your project directory, only the information which jars are needed.
mvn package
This command creates a jar out of your project an places it in the target/ folder of your project.
Local Repository: This is a maven repository stored locally on your machine. It normally resides in ~/.m2/repository/. Every dependency you are using in your project will be stored in this repository. On compiling your project, maven will use the jar files from this location.
mvn install
This command creates a jar file and copies it to your local repository: ~/.m2/repository/groupId/artifactId/version/project.jar. Now you can use this jar in different independent projects as a dependency, but only your machine.
Private Remote Repository: Most of the time this is a Nexus in your company network. This server allows to share the build project across developers. Your TeamCity server builds the jar and copies it to your nexus server. Beyond this the nexus server works like a proxy, e.g. A Developer needs junit-4.1.1.jar, so the server looks for it on public remote repositories and caches it.
mvn deploy
This command builds a jar and sends it to your nexus server ('to your private remote repository') After that every developer inside your company network can access the jar.
Public Remote Repository: These are repositories available on the internet which contain several jar files, e.g. maven.codehaus.org
Summary:
If you call mvn compile maven looks for the dependencies in your local repository. If maven can't find them, it will ask the (private/public) remote repository, and copy the files to the local repository.
You should not synchronize a local repository over network, since this type of repository is not targeted at such use and may break in some obscure way.
What you need is a mvn deploy - copies the final package to the remote repository for sharing with other developers and projects
mvn install you tried will just build and install the project in your local ~/.m2 repository. It will_not publish the artifacts to your nexus repository which you have configured.
Both install and deploy are valid build phase - meaning it executes all previous phases. Please refer to Maven docs below for more understanding.
From maven documentation:
the default Maven lifecycle has the following build phases (for a complete list of the build phases, refer to the Lifecycle Reference):
validate - validate the project is correct and all necessary information is available
compile - compile the source code of the project
test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
package - take the compiled code and package it in its distributable format, such as a JAR.
integration-test - process and deploy the package if necessary into an environment where integration tests can be run
verify - run any checks to verify the package is valid and meets quality criteria
**install** - install the package into the local repository, for use as a dependency in other projects locally
**deploy** - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

Publishing artifacts with sources on archiva

At work I'm dipping my toes in managing project dependencies with maven. We use Apache Archiva (1.2.1) as a local repository and proxy. I'm adding artifact for open source project, that is not published on any public repository. I've learned that to publish the sources I should use the Classifier field on Upload artifact page. The sources are then listed alongside the jar and pom when I browse the repository.
But when I update my maven dependencies I get only the jar and pom from the repository. I noticed that sources are also missing when the archiva proxies for me the downloads from other public repositories. I didn't find any configuration options in Archiva's admin pages to serve the sources... What am I missing?
Update: I was missing the fact that artifact sources have to be downloaded manually. I.e. the maven client has to request them, which is controlled by command line option -DdownloadSources=true. Maven Integration for Eclipse has a preference setting to always download them as described in Resolving artifact sources. Archiva then serves the sources for local artifacts or proxies the request to remote repositories and caches the sources for future requests.
Archiva does serve the sources, but Maven does not request them by default. I know since I also use Archiva as my Maven repo. How are you requesting the sources?
If you're using eclipse
you can run mvn eclipse:eclipe -DdownloadSources=true in the project directory;
you can install the Maven Integration for Eclipse.
Both of them should return the sources if they are available.
The sources aren't required to satisfy compile/runtime dependencies. If you wanted to bundle sources with your app, then you would specify a dependency with a source. Or you would use a plug in like assembly to grab them from archiva.

Resources