Gitlab ci issue with parent and child POM - maven

I have 6 microservices in my project and i have seperated them into 6 projects in gitlab. When i tried to build this microservices all together or after building parent POM later child POM seperately outside Gitlab it is working but while using gitlab-ci i am not able to build it as they are failing non resolvable parent POM.Can someone please let me know how can i build this microservices independently(building parent POM and keeping the artifact available for all other projects).
Tried caching and artifacts in gitlab but they are strightly bound to single project

If you always want to build those six microservices together, put them into one multi-module project. Then you have one project on GitLab and everything will be much easier.
If you need to separate, then you need a Maven package manager. You can use the one that is included in GitLab, or you can use an external one like Artifactory.

Related

What is the best way to structure maven projects to make a client jar?

New to maven here...coming from the ant world
I need to create a client jar with a few files that will give my client the ability to write to my Db and make rest calls to my services.
These are mainly classes that wrap a Rest connection and db client.
Is it possible to produce this artifact as a side effect of my main maven project ?
Eg: main project produces a bundle when I run mvn package, but I'd like to produce the client jar by providing some other parameters....
What you need here is a multi-module maven project.
The structure goes like this:
-- Parent Module
----- Child 1 Module
----- Child 2 module
Here you can have all your code/files of your main app in child 1 module and put all the code/files for the client in the child 2 module.
The parent module is just an aggregator which produces an artifact of type pom. Whereas each of your child modules will produce individual jars.
You can then you the second jar in your client.
For a detailed understanding how multi-module project works, check this link.
The standard Maven way is "one project, one jar". This means that the cleanest way to achieve your goal is to set up a multi-module project where you have one module for your "normal" jar and one for your "client" jar. But there are other possibilities:
If you are talking about an ejb, you can use the maven-ejb-plugin and create a client artifact. Unfortunately, both artifacts then share the same pom (and, therefore, the same dependencies).
You can use the maven-assembly-plugin to assemble a set of files and deploy them as side artifact (same problem as in (1)).
You can use the maven-install-plugin and maven-deploy-plugin to install/deploy entirely different artifacts along with your main artifact. These artifacts need to be created before, e.g. by a custom maven plugin.

separate external artifacts repository and project artifacts repository in maven

As a CI engineer I want all my maven jobs to have 1 local repository with external artifacts - aka projects 3rd and 2nd party dependencies, plugins...
This would save me tons of build time and disk space avoiding downloading from remote repository.
On the other hand, each build job is supposed to have isolated repository to write to.
Is there a way to work 2 separate local maven reposiotories: one for external artifacts and the other for internal?
Another option is to seperate them.by groupId.
Do you know if Gradle support such logic?

Server/Client build using maven/jenkins

I'm asking for recommendation on how to configure our Client/Server build. we have a client server architecture. the versions of the Client and the Server are tightly coupled, meaning,
they are both stored in the same git repository.
during development, changes in Client and the Server must be made at the same time to maintain compatibility in some cases
the Client code is dependant on server code
at the moment they do not share a parent pom.
I'm wondering what would be the best way to have both Client and Server compiled from the same branch. keeping in mind branches are created all the time and developers may run a job on a private branch using parameterized builds.
options:
Create combined parent pom.
Create a Jenkins job and execute 2 maven builds one of the other using shell commands
Add branch name to the version and deploy the server to the Artifactory
Maven modules
You can use modules to aggregate both the client and server projects within the same Maven build. You don't have to have a parent POM in the inheritance sense, but you need one more POM to aggregate the two projects. You'll need the following directory/files structure (normally all POM files are named pom.xml, I renamed them here for clarity):
main-pom.xml
server/
server-pom.xml
client/
client-pom.xml
In main-pom.xml specify the projects to be built in the "modules" section:
<modules>
<module>server</module>
<module>client</module>
</modules>
The module names have to be the directory names. Don't worry about the order, Maven will figure it out according to dependencies.
You can combine this approach with inheritance (the real parent POM) if it makes sense to share properties between your client and server projects (version, common dependencies, plugins, etc.).

mvn release:perform creates multiple staging repos

I have a project that uses maven and I am attempting to deploy to the sonatype OSS repository. When I execute mvn release:perform, 5 different staging repos are created instead of just one. The various files are spread among these different repos so I cannot successfully deploy.
Is there a reason that maven is splitting up my release?
The project along with my pom files are here:
https://github.com/Uncodin/bypass/tree/master/platform/android
Turns out that each staging repository thought that it was deployed from a different IP address. This can happen in corporate environments where a floating IP address proxies outbound requests.
https://issues.sonatype.org/browse/OSSRH-5454?focusedCommentId=180666&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-180666
the parent you are using (https://oss.sonatype.org/service/local/repositories/central/content/org/sonatype/oss/oss-parent/7/oss-parent-7.pom) does not really give a hint on whats going wrong. there is only one release repository configured: https://oss.sonatype.org/service/local/staging/deploy/maven2/
Is it possible this is caused by some configuration inside the Nexus Proxy? And not by your maven structure?

Is there any way to configure Archiva to download missing Maven project modules if they aren't in the local workspace?

I'm confused about how Archiva fully works. I understand that if we had a core set of dependencies, we could use Archiva as our local maven repo.
The thing I don't understand, is how Archiva manages build artifacts from your own projects.
Say I have a multi-module maven project - we can even use the one from the Sonaytpe for example. http://www.sonatype.com/books/mvnex-book/reference/multimodule-sect-building-multimodule.html
What if I wanted to have one team working on the Simple Model app, while I wanted another to work on the Simple webapp. But I didn't want either to have the projects they AREN'T assigned to, in their local workspace. Webapp needs Model to build, but I don't want the Wepapp team having direct access to Model.
Is there any way Maven can detect that the build artifact for Model wasn't in a Webapp dev's workspace, and pull it from our local Archiva repo, so they can still build the Webapp despite not having the model (maven module project) code in their workspace?
The Model project will be like any other third-party dependency and be downloaded by Archiva automatically, provided
the Webapp project specifies Model project as a dependency
the Model project is deployed to Archiva periodically (by a Continuous Integration system or other means).

Resources