How to ship a Spring Boot app from a Gradle Multi Build project? - spring-boot

Let's say I have a Gradle Multi Project with 3 subprojects, 2 Spring Boot projects (auth and profile) and 1 Library project (commons).
The 2 Spring Boot projects include a dependency on the Library project: implementation project(":commons")
Actually, to run the 2 Spring Boot projects, I have to run this from the parent project:
gradlew auth:bootRun
gradlew profile:bootRun
If I run gradlew bootRun only, from each Spring Boot subproject, I get the Error like the :commons Library project is not found in the root project, which makes sense, because the :commons project is included only in the parent's settings.gradle file.
I have to push each Spring Boot subproject individually to Heroku.
How should I manage ?

I finally got it, just add this in each subproject's settings.gradle file, then build:
include ":commons"
project(':commons').projectDir = new File('../commons')

Related

Hot reloading a multi-module spring boot application with gradle

I'm trying to convert a project from maven to gradle, but I'm having trouble getting hot reloading to work the same way. I can't show the actual project so I've created two identical very simple projects. One with maven one with gradle. These projects contain two modules:
project
|____api
|____lib
The /api module contains a spring-boot app which depends on code from the /lib module
In the maven project I can change code in either of these modules and recompile either with my IDE (intellij) or with the maven cli and spring-boot-devtools will hot reload the application. However in the gradle version it only successfully hot reloads code that has changed in the /api module.
From what I gathered this seems like a classpath issue. If you run gradle or maven in debug mode it prints out the classpath it passes when it starts the application. Maven includes <project_dir>/lib/target/classes/kotlin/main. However gradle only includes <project_dir>/lib/build/libs/lib.jar
I'm very new to gradle to I might have some of the build configuration messed up. Here are the two project repo's:
Maven: https://github.com/Perry-Olsson/mvn-hot-reload
Gradle: https://github.com/Perry-Olsson/gradle-hot-reload

How to add a runtime library on Gradle in the build command

I have a build.gradle file that I want to use to build a Spring Boot microservice for multiple projects. I have created a custom library with some classes that should not be in all of the projects but I don't want to have to edit the build.gradle file when I build the microservice depending on which project I will use it in.
How can I add a command/parameter to gradle build that can add runtime libraries to the Spring Boot app?
Something like (just an exaple):
gradle buildDocker -PaddRuntime=com.skios.lib:lib-common:0.2.35
Thanks for any directions
I am not sure I understand your issue fully and thus not convinced this is the best solution.
But since a Gradle build script accepts code, you can have conditionals in a dependencies block:
dependencies {
if (project.hasProperty('addRuntime')) {
runtimeOnly('com.skios.lib:lib-common:0.2.35')
}
}
and then on the command line: ./gradlew buildDocker -PaddRuntime

How to Run multiple spring boot application in gradle

I'm a beginner in gradle need to implement multi-module spring boot rest micro-services
sample source code:git-hub
when I give a bootRun command
actual:
this task is running only demo1 module so that that rest API I can access
expected
Need to run both demo1 and demo2 project in a different port.
Environment: jdk8, spring-boot 2, gradle 5
This is a Maven project for running multiple Boot projects in different ports within a single JVM.
https://github.com/rameez4ever/springboot-demo/tree/master/springboot-multi-service-launcher
Changing Maven pom.xml to Gradle build.gradle might be sufficient. Hope this gives some idea.

Spring Boot Gradle bootRun task default classpath and current working directory

I am going to test external config for application. What is default classpath and default working directory for Spring Boot Gradle bootRun task?
I didn't get in from:
http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-running-your-application.html
https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html
UPDATE test with System.getProperty("user.dir") show that current directory is where Gradle is started.
Working directory is actually the module with Spring Boot project, which does not necessarily have to be the rootProject.
Classpath for bootRun is:
working directory (or Gradle project directory with Spring Boot)
main classes
runtime classpath
At least this is what seems to be the default when I debug the build (now easily possible with IntelliJ IDEA 2018.2).

Spring Boot Initializr: Maven project or Maven POM?

I want to set up a Spring Boot project using the Spring Initializr (https://start.spring.io) but I was wondering about the difference in the project type you can choose between: Maven Project or Maven POM?
What is exactly the difference between these two types?
Maven POM creates only the pom.xml file.
Maven Project creates the pom.xml file and a sample project including src folder:
> src:
> main:
> java:
> com.example:
Application.java
> resources:
application.properties
> test:
> java:
> com.example:
ApplicationTest.java
> pom.xml
Maven Project is the type which we use to create a common Spring Boot application. It seems Maven POM is for downloading build scripts only.
Basic difference that you even experience it by selecting the maven project option and say download, you get a maven which includes sample spring boot application
Other case you have existing project and want to add spring boot then you can simply get the configuration to include spring boot artifacts

Resources