How to override configuration of child project, added as jar in Gradle? - spring

how can we override configuration of dependent child project in a Gradle project for example.
I have 2 Gradle project.
project 1 : this project has actual business logics.
project 2 : this project specified a flow of the execution with the help of spring boot.
now project 1 has dependency on project 2 as jar.
project 1 -> build.gradle -> project 2(as jar)
now as we can see project 2 only has flow, and all the business logic and structure is in project 1. so how can I pass details of project 1 to project 2.
like
configuration class,
base project (for component scan)

Related

Mule 4 : Can Mule 4 Domain Project be used as a Maven Parent Project for other mule apps?

Scenario : I want to create a common project for all my mule applications that can do the following:
Aggregate all Mule 4 component configurations for child projects (like Salesforce Config, DB Config etc)
Aggregate all maven dependencies for any jar used in child projects for example mssql JDBC maven dependency etc.
Point 1 can be handled by Mule 4 domain project and
Point 2 can be handled by a Maven Parent project.
As per Mule Documentation : https://docs.mulesoft.com/mule-runtime/4.3/shared-resources#associate-a-mule-app-with-a-domain-using-studio. we have to refer a domain project by specifying it as a normal dependency.
Can we instead define it as a parent pom?
I don't recommend to do that. A parent pom has a different intention, and mixing them might be confusing to developers. It might also confuse the Mule Maven Plugin when building applications, which doesn't provide any support for this kind of scenarios.

Converting existing project to Spring boot project in InelliJ

I have an existing project. I need to make it a Spring boot based project and I am using IntelliJ CE.
What would be correct procedure for doing it?
Edit:
Project has no initial structure. It is a totally empty project. So no existing modules etc.
Spring Boot is an Ultimate feature, so first you would need to try/buy the IntelliJ IDEA Ultimate.
From there, you can add Spring support to existing project modules or use the Spring Initializr wizard to select the necessary configuration when creating a new project or module.
In your maven pom.xml or build.gradle file, I would add the spring boot starter dependency:
spring-boot-starter (the group id is org.springframework.boot)
If the application is a web application, I would also add the web starter spring-boot-starter-web also with the same group id (org.springframework.boot)
For convenient features, applying the spring boot plugin would help in creating a runnable jar with all required dependencies bundled called a fat jar.
A great tool I use is the spring boot project generator. It allows you to configure the modules you want and create a project template.
Spring Boot requires IntelliJ IDEA Ultimate. If you want to use IntelliJ CE, please create a project using Spring Initilizer then import the same to your IntelliJ CE (File -> Open -> Choose the project root folder). After you import the project, wait for some time so that IntelliJ can download the dependency and build your project. You can check from (Build -> Build your project). Then find the main class of spring boot and run it using the green play button

Spring boot app in another project from controller class

I want to know if I can keep my Spring boot class in Project A and my controller and services in Project B and invoke the end-points from Project A? The reason to do this is because I want to give Project A (which has dependency of Project B) an option to extend my controller and services to override any method.
Yes, it is a common practice to have your starter in a project and the libraries in another (spring projects are a good example for it).
it is better to have them separated in 2 repositories :faster build, version management, separation of responsibility between team members etc.
Build the project with the libraries (A)
Project with the starter (B) will have a dependency to project A
In general, it is recommended to have a configuration in project A with #ComponentScan and project B should import the configuration.
If the beans are scanned from project A, you will have access to all endpoints and services.

Spring Boot multi module WAR Generation

I have made a maven Spring boot (REST) Project that has 3 (maven) sub modules (i. api ii. implementation and iii. service modules).
The main method (#SpringBootApplication) is in the root of the project. The REST web service works fine from IDE but maven does not allow me to package this project as war and deploy to external tomcat.
To solve this I added a new module and added dependencies of other modules within this and packaged this as war (by adding maven-war-plugin). But when deployed on server; the webservice does not get hit.
Structure-
Service Project
main()(This is within root project)
api module
service module
implementation module
Newly added module (that has above 3 modules injected as dependency and the plugin that let me package this as a war)
Expecting a war that has all these submodules that can be deployed on external Tomcat 9 server.
How to achieve this?
Please Note - I have added spring-boot-maven-plugin
to repackage in the root project, but it is not working.
Adding parent to this newly added module fixed the issue and I was able to make a working jar!

Web project dependency pojos, web deployment

I have 3 maven projects:
1 - common pojos project
2 - web project
3 - java client project
web and java project uses same pojos from common project, have dependency on 1 project
I added to web build path common pojos project,
but when I deploy web project to server, no pojo classes exceptions....
My question is how can I configure it to get my pojos classes deployed with all web project ?
(it will be fantastic, If you have some online examples for this)
Tnx.
If all your 3 project are maven projects and the dependencies are set right then maven will automatically package all the dependencies into the war.
commons pojos is a jar project
web project is a war project which depends on commons pojos project. Unless the dependency scope is not provided the jar will be packaged in the war.
You can verify the same by opening the war file as see if the commons pojos jar is present and the jar has the required classes.

Resources