How to build a container from multiple Maven projects [closed] - maven

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am creating a microservice to deploy on the cloud using Docker and Kubernetes. This requires code from multiple Maven Java projects that are not on any public repository. For example, the microservice project has a dependency on a analytics project which has a dependency on a model project. There is no inheritance between the POMs of these projects. Locally, the microservice Maven project builds successfully using the artefacts already in the local Maven repository. However, when I try to build a container from the microservice project, it fails because Maven in the docker build cannot find the analytics and model jars in the container's Maven repository.
What are my best options for making the model and analytics projects available to the image build so that I can build the docker image?

So the build within docker can't see the artifacts that are only installed in your local maven. If they logically fit together (i.e. they're only ever used together) then it would make sense to combine them into a single multi-module Maven build with a single parent pom. It sounds like this could be your situation.
Otherwise your best options are:
1 Host the artifacts that docker currently can't see in a public repo. If you have a nexus you can use you could install them there.
2 Build your jar outside docker and copy the artifact in. This means a change to your dockerfile and effectively a Maven pre-docker step in your build.
3 A variation on 2 but combine the Maven and docker steps with a Maven plugin. For example you could use the Spotify docker Maven plugin.

Related

Cannot resolve dependencies in spring boot when creating a new application [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Error occurs when creating a new application n try to download n build dependencies for the app. I Cannot resolve dependencies when creating a new spring boot application in intellij.
Resolve dependencies error
Cannot resolve org.apache.tomcat.embed:tomcat-embed-core:9.0.50
Cannot resolve org.springframework.boot:spring-boot-test-autoconfigure:2.5.3
Cannot resolve org.springframework.boot:spring-boot-test:2.5.3
Cannot resolve mysql:mysql-connector-java:8.0.26
Cannot resolve org.springframework.boot:spring-boot-starter-test:2.5.3
Cannot resolve org.springframework:spring-jcl:5.3.9
Cannot resolve org.springframework:spring-test:5.3.9
How do i solve these issues. Spring boot 2.5.3
You will have to go to your .m2 folder on your machine depending if you are using windows it should be in
C:/Users/username/.m2 and delete the content of that folder.
Of course, you need to be sure that you have dependencies in your pom.xml that are complaining about, if you do have all dependencies, you can go to the next step.
Go back to your IntelliJ and you can run two maven commands ( clean, install ), you can either run them from the terminal of your IntelliJ, or you can run them from maven UI which is located on the top right side of the IntelliJ, next to database UI.
try this two things
1> building project from console,if not work.
2> if it is a new project try to create project create project using spring initilizr
second approach is recommended.

Need to run ReadyAPI using maven project with jenkins as CICD approach

Run the ReadyAPI project using maven with help of jenkins.
I have already created a regression suite in readyAPI as xml format.
Created a java maven project using pom.xml
jenkins job has been created to run the ReadyAPI suite directly but want to run using the java project which include pom.xml
Run the ReadyAPI project using maven with help of jenkins.
Need to provide some videos in which i can solve the issue which i am currently facing.
I think you need to split this question into two concerns:
How do you call Maven from Jenkins?
And once you've got that, you need to think about...
How do I run a SoapUI/ReadyAPI project from Maven?
The first question is addressed here:
https://www.youtube.com/watch?v=pts8zdHel5E
The second question is addressed here:
https://support.smartbear.com/readyapi/docs/integrations/maven/example.html
If you have already covered the basics here, and got some specific problem, you need to provide more information to your specific situation.

Can I automate my spring-boot docker builds with the dockerfile or would Jenkins be more appropriate?

After first attempts of setting up automated docker builds for my personal spring-boot github repos (I'm a newbie) they were constantly failing due to the jar file not being found. While my first impression was that I had the pathing wrong, it dawned on me that docker wasn't building the jars before attempting the builds.
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE=target/myjar*.jar
ADD ${JAR_FILE} myjar.jar
EXPOSE 8080
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/myjar.jar"]
While I have found a couple of resouces that describe how to integrate maven into the Dockerfile, it seemed like my image could easily get too big too easily with that approach. Has anybody tackled this issue before and could recommend recommend a way to integrate maven into the Dockerfile build? An alternative I've given thought to is to learn Jenkins and develop a solution that way for a pipeline.
There are many approaches to achieve this.
Approach 1
Rely on the maven with its docker maven plugin
This indeed allows building the image during the maven build.
This approach will work in general and allows a level of customizations sufficient for
many use cases. Usually, spring boot applications come as a single Jar with all the dependencies packed inside it, so there is no need for multiple layers in docker image (at least in my experience).
The point here is to call the plugin when the jar of spring boot is already built.
The jar is prepared with the help of another plugin and it is usually invoked in package phase, so if you go with this approach, make sure that you invoke the image creation plugin after the spring boot maven plugin that builds the single jar artifact.
The artifact must reside in <you_module>/target folder and it will be pretty big in size. The original module will reside next to it but will have the suffix .original.
Approach 2
Let maven build the artifact but not the image. Maven will end after this step.
Then invoke a script in Jenkins that will run the docker build command and it will build the image.
The result will be the same, you'll work here with docker directly possibly utilizing all its perks if you really need it.
Both approaches can work for you, choosing between them depends on the following factors:
You're more a Java / maven guy rather than devops guy - then go with approach 1 otherwise go with approach 2
You would like to actually locally run the image that you've built, for example, if you have a kubernetes cluster installed locally - in this case, go with approach 1
You need to utilize some latest features of docker not available for use from the plugin - then go with approach 2

ANT Vs MAVEN comparison with respect to Build time [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 months ago.
Improve this question
We are currently using ANT as our build tool and we are proposing our developers to use Maven as their build tool.
Our developers are resisting this change and asking us to give the benefit we will achieve by migrating to Maven. From the blogs what I read Maven can help in reducing build time when compared with ANT.
Can you please give us any reasoning how MAVEN Build script can reduce the build time when compared to ANT? Is this statement true in the first place?
NOTE: Ours is a legacy application that is developed in Core Java.
Are there any other powerful features in Maven which might pique interest of developers that can help us get their confidence in migration to Maven?
Transitive dependency resolution, standardised builds, lots of plugins, works with Maven repositories which are the de facto standard for storing Java artifacts.
maven can be faster than ant, if you know how to
structure your code into modules
use parallel build of (multiple) modules (a feature ANT really don't has)
use semi-incremental build (use newest compiler-plugin) - build only modules, which have changed files or which depend on other changed modules
other benefits are
maven can help you, to describe your build in a more standardised and structured way
standard project layout (folder src/main/java src/test/java ...)
clear build-process with a strict path of executed steps
clear definition of used dependencies
thirdparty dependencies
in-project dependencies
many helpers for a clear CI/CD setup like
plugins supporting gitflow
plugins supporting special release processes
plugins supporting integration-testing

Purpose of POM.xml in Maven [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am very new to Maven. I have the following questions:
Do we need to create POM file our own?Do we need to understand POM file fully to use Maven?
We are mentioning Plugin in the POM. will that plugins only be downloaded by Maven when use Maven? or by default all plugins will be downloaded?
Please explain.
First you need to understand the pom content otherwise you are not able to influence the build process. The pom file should be created manually but there are some exceptions like Spring Roo which will create the pom but it's better to understand the pom to see if something is going wrong.
The plugins mentioned in the pom will be downloaded automatically by Maven but there are plugins which are by default in the life cycle which will be downloaded as well in contradiction to naming them in the pom file.
You need at least to understand some basics of Maven: dependencies, how to configure plugins, how to start a new POM (you can do this in IDE or create a project from an archetype), basic commands: mvn compile, mvn package, mvn install. If your only need is to build your classes into JARs, Maven configuration would be as small as a list of dependencies.
Everything in Maven is downloaded by default - all artifacts are being searched in Central and any other configured repositories. Once downloaded, they are stored on your machine at $HOME/.m2/repository.
Might be helpful: Maven Quick-start Guide.

Resources