Push jar-file to gitlab maven packages for CI - java

I am using maven to write a java program and i have a gitlab repository. Now i want CI to run my junit-tests. So i am creating a maven-docker and try to run them, but it fails because of a missing dependency. The dependency is not available in the docker.
The dependency is in my local maven repository because i added it. There only exists the jar-file and it is not available in a public repository (it is beautyeye-lnf). How can i push the jar-file to gitlab maven packages?
I have read the following article, but wasn't successfull (i do not have a project, just the jar-file)
https://docs.gitlab.com/ee/user/packages/maven_repository/
Is this possible? Or do i not understand the docs?

Create your maven image and copy your jar file inside. So you can use that image as base image.
Example;
FROM maven:3.6.3-openjdk-8
COPY (dependency files or jar) ./root/.m2/
docker build -t maven-build-image:latest .

Related

Convert beam pro API on GitHub to jar file

I tried using the beam API in Java, but to use it inside of Eclipse, i need a JAR-File of the API. I wasn't able to convert the API on GitHub into a JAR.
And yes i tried converting it using Maven ...
Can anyone convert the API to a JAR file for me, or is there another way to convert it? Here's the GitHub link: https://github.com/WatchBeam/beam-client-java
If you want to build the jar file yourself from the github repo, then you need to clone the repo, run the maven build, and copy the jar out of the target directory.
git clone https://github.com/WatchBeam/beam-client-java.git
cd beam-client-java
mvn clean install
cp target/api-3.0.2-SNAPSHOT.jar /path/to/some/dir
If you're content with just downloading the jar, you can find it in beam's maven repository here: https://maven.beam.pro/content/repositories/snapshots/pro/beam/api/

How to add java library without no repository to pom file?

I'd like to add one project A as my dependency, but unfortunately, there's no repository host this library. I know that I can install it to local repository manually, then refer this in pom file. But I have a travis build job where there's no such artifact, is there any way that I can install this library to local repo automatically ? Thanks
I would recommend to use the clean approach and uploading this library into your own repository. If you don't have one: time to get one running.
If you're really not up to this task the maven install plugin: http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html can install a jar in the local repository. This will work both locally and on a CI server.
To upload a jar in a remote repository there is the deploy plugin: http://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html
If you bind the execution of this plugin to a very early phase in the maven life-cycle (validate) you might be able to avoid a build step required prior of your own build.

Download a Maven artifact and install into a specific local repository (not .m2)

I have several local Maven repositories besides the one located in ~/.m2 directory and I want to simplify the process of installing new artifacts into them from Maven central.
So far I couldn't find a way to tell mvn dependency:get that dependency should be put into a specific local repository.
I did manage to find a way to install a given downloaded artifact using mvn install:install-file -DlocalRepositoryPath=, but I want to be able to get and put dependencies into a specific repository with as few manual steps as possible.
Before you ask why can't I just configure my project to use Maven central directly here is the answer: the project uses Gradle and I do not own its build script (i.e. I can't modify it). The project build script is written to work with several distinct repositories having the same base URI that I fortunately can change using build.properties file. So my idea is to have several local maven repositories in the same root directory and trick the build script to use them.
You can use the maven.repo.local property:
mvn dependency:get -Dmaven.repo.local=/path/to/localrepo

Maven and m2e - build jar with dependencies information

We are using Maven and m2e tools for our development and today we encountered a problem.
One of our projects is small library that is required for other projects, so we packaged it into jar file and put in our private Maven repository.
For now, all of the jars that we put in this repository didn't have any external dependencies, but this library I mentioned uses some external jars.
Now, when I add information about this jar to other poms, this jar is downloaded from our private repository but Maven doesn't download dependencies needed by this jar.
I am wondering if I need to use some special target/add something to my pom.xml file that will inform Maven to include information about dependencies needed by this artifact.
EDIT:
Here is the workflow I perform when I upload jar to our private repository:
1.I generate jar file from Eclipse using m2e
2.mvn install:install-file -DgroupId=<your_group_name> -DartifactId=<your_artifact_name> -Dversion=<snapshot> -Dfile=<path_to_your_jar_file> -Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true
3.I copy folder created in my local repository to remote repository
If your small library is a maven project as you state, there should be no reason to have eclipse build the jar and then use maven to install it and then manually copy to the remote repo. Instead you should use m2e to run the deploy goal:
mvn deploy
That will cause the jar to get built and then install it directly into your local maven repo then deploy it to the remote repo.
In eclipse this can be accomplished by right clicking your project, choosing Run As -> Maven Build... then in the run configuration window for Goals input type deploy then click Run. After this has been done once, you can just use Run As -> Maven Build to run the same config again.
I see you use -DgeneratePom=true during the installation of the jar file. What you need to do is create a pom.xml for your artifact. In the pom.xml, you can specify the dependencies that your jar file requires. When executing the install:install plugin goal, you use -DpomFile=pom.xml instead.
The best way to do this is to run mvn deploy
You have to setup the distribution repository to your private artifact manager (nexus or artifactory) in your settings.xml
see this for more details

Including the Jar of a Maven Project in another Maven Project does not work but including the Project in another Maven Project works

I have 2 Projects namely Project_1 and Project_2.
Both projects are Maven and I am using Netbeans.
I want to include the jar of Project_1 in Project_2 which I am doing like this.
The problem is when I include the jar I do not get any compile time error, however I get a NoClassDefFoundError exception at runtime.
When I include the Project_1 in Project_2 by performing the steps mentioned here. (The Open Project example). I do not get any errors. Neither runtime nor compile time.
Can you please explain me what am I missing here?
Update
Project_2 is deployed on a Server which is not in my local machine however Project_1 is in my local machine.
Inclusion of Project_1 into Project_2 as a project was done for testing in my local machine.
First of all, a good rule of thumb to adopt is never use the system scope and system path to pull in dependencies. In my experience there's always a better way :-)
If Project_2 depends on Project_1, then first install it's jar into the local repository:
cd Project_1
mvn clean install
Watch the output you'll discover the jar is placed somewhere under the following directory:
$HOME/.m2/repository
Once this is done the jar will be available as a normal dependency to the second build
cd Project_2
mvn clean compile
The local repository ensures the projects are now decoupled from each other. Assuming you're using snapshot revisions of Project_1, the Project_2 build will always retrieve the latest revision built and tested.
Update
You should use a Maven repository manager to share jars between machines/teams. Recommendations are contained in the following answer:
Share jar of the module with another team
How to configure Maven to use a repository like Nexus is described in it's documentation.
As described in the deploy plugin documentation you'll need to add a distributionManagement section to your POM (detailing the repository URL) and then upload the project's jar to your repository as follows:
cd Project_1
mvn clean deploy

Categories

Resources