How to execute only image build with spring boot maven plugin - spring-boot

I'm using Spring Boot 2.5.x and I create the docker image with the following command
./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=myImage
The goal "build-image" seems execute the "verify" also.
Is it possible to execute only the build image without redoing the build of the project?

Is it possible to execute only the build image without redoing the build of the project?
Not currently, because spring-boot:build-image forks the Maven lifecycle to run the package phase. The design is discussed in a Spring Boot issue. There isn't a good solution yet to meeting the needs of both uses cases (the current use case of running spring-boot:build-image without requiring a jar to be built first, and the use case of not re-building when the jar is already built).

Related

Springboot 2.3 with Docker. I want to build image for a specific app when I have multiple springboot applications in same repository

Building a springboot application version 2.3. I want to build a docker image with the cloud native build packs. I have 2 springboot applications sitting inside my repository, say App A and App B. Usually, I do mvn install, pick up the jars and start them individually. Run jar "a" for aapp a and jar "b" for app b. Now, How do I tell the build pack on which jar I want to build my docker image on.
Building on a stack of other answers, you can use the advanced reactor options to target a single module in the reactor and build the image just for that module.
A command like
mvn -pl <module-name> -am spring-boot:build-image
will likely give you what you're looking for.
Whichever platform you're using, you should be able to point the build toward your relevant subdirectory. For instance, if you're using pack, you can use pack build -p <repo dir>/<app A dir>. Depending on which Java buildpack you're using, it should run Maven for you and set up the resulting JAR to launch when the app image is started.

Use java S2I for spring boot app with gradle build in openshift

How to get started with java S2I build for spring boot application with Gradle build?
Please suggest me any Json/yml file needs to be imported to get started.
Here is a whole repo - https://github.com/dsevost/gradle-s2i - with a Dockerfile to build a S2I gradle builder image, and a template to build applications on top of it.
Perhaps it is worth noting the BUILDER parameter in the template with possible values of 'Gradle' or 'Maven'. According to the assemble script, it will build a gradle project even when both pom.xml and build.gradle are present in the project directory.
I haven't tried it myself but I glanced over the template and it looks OK...assuming the image and S2I scripts are functional.

Running API tests in Teamcity build step

I have a Spring Boot Maven app. There is a bunch of API tests using RestAssured, inside the project. These tests are not marked as #SpringBootTest, therefore when running them, the context of the application is not raising so to make tests pass the application must be up and running before.
I'm creating a Teamcity build in which I want to:
Start the app
Run RestAssured tests
Create an artifact
I'm using an Agent with maven installed.
The question is:
How can I create a build step where I run the application on a defined port and then run api tests
against it?
What I've tried is creating such build steps:
Command line: mvn spring-boot:run & sleep 50s mvn test
Maven step/command line: mvn clean package -DskipTests
I thought the spring boot application will start and tests will be ready to start after some time. On successful step 1 I create an artifact.
The problem is that the build step is never exited because of spring boot app running (blocking terminal).

maven plugin for docker (e.g. to run with needed db)

Making an image for maven project should be straightforward, as maven know how to build (and can know how to run)
How to build docker image and run it with maven?
Let's say the app also needs MongoDB, that I can run as docker run -p 27017:27017 mongo. Is it possible also to specify with some maven plugin?
The maven plugin created by fabric8 allows you to do this:
the plugin and its documentation is available on github: https://github.com/fabric8io/docker-maven-plugin
The samples include for example https://github.com/fabric8io/docker-maven-plugin/blob/master/samples/data-jolokia-demo/pom.xml (which seems to be similar to what you plan).
An alternative could be using Docker-compose and some scripts outside maven, once the images are created.

What is the purpose of tomcat-maven-plugin?

I'm having some difficulty understanding the purpose of this plugin. Is it to modify the settings in Tomcat during the build?
I am deploying to tomcat using maven, without the plugin and it seems to work fine. Not sure if I am missing something
Cheers
Maven Tomcat plugin basically just bootstraps an embedded Tomcat container for you. Saves you the trouble of configuring an external Tomcat instance for development purposes. It can also auto-start this Tomcat instance during the build and run integration tests on it, stopping it afterwards.
If you already have a functioning workflow that you're comfortable with, no need to introduce the plugin, but it's pretty easy to configure, can run multiple web apps, can run unassembled applications etc so it's convenient to have for local development.
An even more light-weight alternative would be the Jetty plugin which starts an embedded Jetty server instead.
Maven is actually a plugin execution framework where every task is actually done by plugins.
Maven Plugins are generally used to :
create jar file
create war file
compile code files
unit testing of code
create project documentation
create project reports
A plugin generally provides a set of goals and which can be executed using following syntax:
mvn [plugin-name]:[goal-name]
For example, a Java project can be compiled with the maven-compiler-plugin's compile-goal by running following command
mvn compiler:compile
for more information go to http://www.tutorialspoint.com/maven/maven_plugins.htm
so pulgins is used to execute goals.
suppose if you don't include plugin that is required in your execution environment then it will throw an error like
A required class is missing: Lorg/apache/maven/plugin/BuildPluginManager;
so by adding appropriate plugin in pom.xml it will resolve the dependencies and execute the goal succesfully.
to remove above error just add the following plugins :
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-amps-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
</plugin>
Maven is a framework used to build JAVA applications, it provides the following
Directory Structure
Configuration Files
Build Settings
It helps in easy and structured development, primarily used for REST API Calls.
Applications built on Maven Framework, would require the same to be deployed
Its better that you get the plugin installed, since on a long run you never know what dependency may go missing
-If this helps, Mark as Answer

Resources