Gradle Multi-module project : Beans are not getting scanned from other modules - spring-boot

Parent module
-- module 1
-- module2 (SpringBootApplication class resides here)
-- common module (Declared an interface ABC.java)
All my packages starts with com.xxx (in all modules) which I mentioned in scanBasePackages as below.
#SpringBootApplication(scanBasePackages = {"com.xxx"} ...
I have beans in both module 1 and module 2 implementing interface ABC.java
Problem :
Beans inside module1 is not getting scanned.
when I try to autowire ABC.java (interface) only Beans from module 2 is getting injected.
module1 beans are not getting injected.
I checked several solutions where they suggested to have common basePackage which in my case have no problem with that.
Note : Similar project in maven is working fine

Related

javax.enterprise.inject.UnsatisfiedResolutionException:Unsatisfied dependency for type com.test.model.TestService and qualifiers [#Default] in Quarkus

I have created Quarkus project and added a SpringBoot project dependency in build.gradle file, dependency downloaded successfully.
Now when I am trying to inject a class which is available in dependancy, the build is getting failed.
Note: The Class which I am trying to inject does not have #ApplicationScope annotation.
getting below error:
Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type com.test.model.TestService and qualifiers [#Default]
Look here:
https://quarkus.io/guides/cdi-reference
See the section 1 in the document above about creating the bean archive.
What worked for me is adding references to the dependencies in my application.properties.
quarkus.index-dependency.[name].group-id=[group]
quarkus.index-dependency.[name].artifact-id=[artifact]
For instance, in my project I injected some OpenTracing beans, ended up with:
quarkus.index-dependency.opentracing.group-id=io.opentracing
quarkus.index-dependency.opentracing.artifact-id=opentracing-api

How to access only one class from different module in multi-module spring boot application gradle?

I have 2 modules (Module A and Module B) in my multi-module spring boot application, build using gradle.
Now the Main class for spring boot module is present in Module A.
Now I want to access this Main class in Module B.
In Module B, I want to write integration test cases and over a Test case class, I want to mention Main class in SpringBootTest annotation. Something like this:
#SpringBootTest(classes = Main.class,
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class TestController {
}
But here I am unable to find the Main class. What changes should I need to make in gradle file for Module B to support this?
It is best to split your project into modules.
Your settings.gradle and build.gradle should look something like this:
settings.gradle
include 'moduleA'
include 'moduleB'
moduleB/build.gradle
dependencies{
implementation project(':moduleA')
}
More info: https://docs.gradle.org/current/userguide/multi_project_builds.html
If you really want to only have the class as the source file, then this should work:
sourceSets {
main {
java {
srcDirs 'path/to/the/class'
}
}
}

Can not import class after added in build.gradle.kts

I generated spring boot kotlin project with spring initializer in intellij.
And added lib dependency in build.gradle.kts after auto generated.
Implementation "org.springframework.boot:spring-boot-starter-security".
I tried import WebSecurityConfigureAdapter, but intellij is 'No suggestions'.
I could not import class after added in build.gradle.kts.
And i tried Run Configurations build, buildDependents, clean, etc...
How can I fix?
Refer to Kotlin Gradle DSL specification. Use
implementation("org.springframework.boot:spring-boot-starter-security:2.2.6.RELEASE")
to declare dependencies.

Quarkus - Unable to inject a RestClient for an interface defined in a separate jar within a multi-module project

I have a multi-module project setup. I am able to use #RestClient based injections for interfaces that are part of the same module (and registered with the #RegisterRestClient annotation).
E.g.,
my-project
|
|- module-1
src/main/java/mypackage
RestAPIInterface.java
src/test/java/
#Inject #RestClient RestAPIInterface -- works
|
|- module-2
src/main/java/myOtherPackage
SomeBean.java
#Inject #RestClient RestAPIInterface -- does not work
Do I need to enable any specific features / switches in order to get this working?

Spring Boot Gradle plugin - Multi Module fat jar

I have gradle multi-project that looks as follows:
-Project
|
|- common
|- moduleA
|- moduleB
moduleA is Spring Boot app and its gradle build file uses SpringBootGradle plugin. This module depends on common nodule.
moduleB is also Spring Boot app and its gradle build file uses SpringBootGradle plugin. This module depends on moduleA.
After I build my Project with gradle build I expect that moduleA.jar and moduleB.jar exist and they do.
But when I try to run moduleB.jar I get an exception (Spring Boot initialization exception). As I found moduleB.jar contains lib directory with all dependencies from moduleA as well as moduleA.jar (which is packaged with dependencies also).
So what I need is to find a way to add moduleA plain jar as a dependency to my moduleB during the build.
You need to configure module A so that it can be used as a dependency:
bootRepackage {
classifier = 'exec'
}
This will mean that you end up with two jars. One without a classifier that can be used as a dependency, and one with a classifier that is the executable fat jar with dependencies nested inside it.
For Spring Boot 2.3 use
bootJar {
classifier = 'boot' // or whatever
}
The fat jars (for module A and B) will have the name *-boot.jar and module B will include only module-a.jar
See here

Resources