Working with multiple module using Maven for Automation - maven

I have a problem and i have confidence that you guys can clarify it.
I have created a java based automation project using maven project structure. I have applied the concept of Page Object Model in it. My project structure is like below.
Automation
Module1
|_____ FrameworkCore.java
|_____ FrameworkWebDriver.java
|_____ DynamicMethodCalling.java
|_____ RunSuit.csv
Module2
|_____CommonPage.java - extends Framework core
|_____Pages
| |_____ LoginPage.java
| |_____ HomePage.java
| |_____ ContactPage.java
|_____Test
|_____ Test1.java
|_____ Test2.java
--> I have created test functions in Test1 and Test2 and i am dynamically calling the methods based on the methodName.
-->In order to achieve the above i need to configure the Module1 as depenency in Module 2
("in-order to refer the webdriver defined in framework code")
AND Module 2 as dependency in Module1
(in-order to call the methods from Test1 & Test2).
This causing the circular dependency.
Is there any way to avoid this circular dependency???
Note: i have searched a lot in the internet and have not found any suitable solution for this issue
Regards,
SomeshKumar Nagarajan

Related

Quarkus ClassLoader gRPC/protobuf and Library

we are using Quarkus with gRPC and some internal library that also uses the same protobuf data. So the dependency graph looks as follows:
quarkus-project
|
+--> lib
| |
| +--> my-protocol.proto
|
+--> my-protocol.proto
Our current solution is a maven artifact (my-protos) that wraps the my-protocol.proto and also includes the generated sources from that.
As Quarkus also needs the raw *.proto file to generate Mutiny wrappers around it, we also include my-protocol.proto via git submodule, s.t. we end up with the following structure:
quarkus-project
|
+--> lib
| |
| +--> my-protos
| |
| +--> my-protocol.proto
| +--> <generated sources>
|
+--> <git submodule> my-protocol.proto
|
+--> <mvn exclude> my-protos // are generated by quarkus again
The compiler checks that the classes to be generated from this proto are already present. So we had to exclude the dependency my-protos via maven dependency management.
Works inside IDE, all classes are present.
BUT as soon as we run Quarkus in dev mode (mvn quarkus:dev), the QuarkusClassLoader throws a ClassNotFoundException when we access a protobuf-generated class inside of the library-code. Checking the stacktrace, we see that the class we are trying to load is a banned dependency. We assume this is caused by the <exclude> in the pom.
Accessing the same class from code that is witten inside the quarkus-project, we do NOT see the exception.
So our best guess is that we are currently dealing with different classloaders (see [1]). The classloader, which is responsible for loading the libseems to have the banned dependency, the other one not.
This explanation is confirmed by running quarkus in production mode (where only the system classloader is used) and there we do not have the banned dependency problem there.
Please send help :)
[1] https://quarkus.io/guides/class-loading-reference

How to setup multi-project IntelliJ workspace with Gradle?

Hello I am working on using Gradle to build a few services. I tend to have seperate repositories for each "code package" i.e. library or service.
In IntelliJ, my setup tends to be the following:
- IntelliJ Workspace
-- Service A
--- pom.xml
-- Service B
--- pom.xml
-- Library A
--- pom.xml
-- Library B
--- pom.xml
Service A & B both depend on Library A & B. This works great, within a single IntelliJ Workspace I can modify Library A and B and startup the services and all is well.
I know you can do composite builds and multi-module builds with Gradle but like I said all the 4 modules above are seperate repositories so this won't work well.
Will IntelliJ support a similar setup as above with Gradle where it recongizes that Library A & B is the library that Service A & B depend on? Or does everyone do a manual publish to Maven local for this consistently?
Thanks!
Rephrasing your question -
there are 3 separate gradle projects service1, lib1, lib2
service1 depends on lib1 and lib2
what is expected is
for local development - where source for all 3 projects locally exists - use the local code build
refer to the repository artifacts if local source does not exist
Assuming a simple folder structure like this.
app-code
- service1
- lib1
- lib2
service1 - settings.gradle
rootProject.name = 'service1'
include ':lib1'
project(':lib1').projectDir = new File('../lib1')
include ':lib2'
project(':lib2').projectDir = new File('../lib2')
service1 - build.gradle
dependencies {
implementation (project(':lib1').projectDir.exists() ? project(':lib1') : 'com.lib1:lib1:1.0.0')
implementation (project(':lib2').projectDir.exists() ? project(':lib2') : 'com.lib2:lib2:1.0.0')
}
how intellij import looks

Spring Boot Multi Module Integration Test

+--------------------------------------+
| Parent module: com.company.project |
+----|---------------------------------+
|
+----- WebApp module: com.company.project <-- #SpringBootApplication
-
+----- Module A : com.company.project.moduleA
-
+----- Module B : com.company.project.moduleB
-
+----- Module C : com.company.project.moduleC
I have a maven structure like one above. Each module is a kind of "service" so it contains many types of components (jpa, web etc). I package the project using webapp module as the entry point.
I want to place integration tests on each service/module since they are independent and I think they "belong" there. Of course when I use #RunWith(SpringRunner.class) spring can't find components and run the tests. How should I tackle this problem?
Thanks

Why parent project classes is not accessable in modules

I am trying to access some files of parent project into sub modules, but i am unable to access that.
My project structure looks like
project
|---build.gradle
src
|---main
|--java
|---EnvConfig.java
API_MODULE
src
|----main
|---java
main build.gradle looks like
dependencies {
compile("org.springframework.boot:spring-boot-devtools")
compile project(":API_Module")
}
I want to access EnvConfig class in API_Module which is in parent, how i will do this. I am already compile API_Module in parent build.gradle, should in compile parent in child. I think it's not a good practice. Please suggest me the good practice.
Thanks
Not much experience in Gradle, but this is obviously more related to your design of packaging and dependency of modules.
For a typical Maven multi-module project (which should also be safe to apply in Gradle), what you are trying to achieve should look like:
project
+ project-core/ <- things share across modules
| + src/main/java/
| + EnvConfig
|
+ project-api/ <- Your original API module
| + dependency: project-core
|
+ project-mod2/ <- Some other module that need to use EnvConfig
| + dependency: project-core
|
+ project-main/ <- Your original top-level project,
| which build on top of project-api & project-mod2
+ dependency: project-core, project-api, project-mod2
This would not work as adding a dependency from API_MODULE to parent will create circular dependency.
Are you sure your main build.gradle needs to have a compile dependency to API_MODULE?

Sonar Report + Multi module maven + Jacoco plugin

I am new to Sonar.
I have multi-module maven project.
please find the Project structure below
-Parent
| -Module A
|
-pom.xml (Module A)
| -Module B
|
-pom.xml (Module B)
| -Module C
| |
| -pom.xml (Module C)
|
--pom.xml (parent pom)
Note : (Module C is shared module in Module A/ Module B - means Internally module C will the part of into Module A , Module B library)
Based on the Project requirement we have these structure.
Module A - works for external users.
Module B - works for internalusers.
Module C -common b/w both the module.
I am trying to create single sonar report for both the module, but I am not able to integrate all the module junit report (Module A and Module B report)
into single report.I followed couple of example to combine the muti-module maven porject but nothing works.
similar issue1 similar issue2
github-example (reference given in sonar)
I had similiar problem with over 40 modules which were even nested. What you have to do is to create whole sonar configuration in parent pom.
<sonar.host.url>set url here (default is localhost)</sonar.host.url>
<sonar.login>user for host url (default admin)</sonar.login>
<sonar.password>password for host url (default is admin)</sonar.password>
<sonar.projectName>optional name for whole project in sonar view</sonar.projectName>
<sonar.projectDescription>optional project description for sonar view</sonar.projectDescription>
<sonar.projectBaseDir>like name says you can set project base dir, if you have parent pom as a separate module then you can type ".." to set main directory with all modules</sonar.projectBaseDir>
Set properly all modules which will be analysed separately for the whole project:
<sonar.modules>module1, module2, module3</sonar.modules>
Configure each one of them properly:
<module1.sonar.projectName>module1</module1.sonar.projectName>
<module1.sonar.projectBaseDir>module1/</module1.sonar.projectBaseDir>
<module1.sonar.sources>optionally set sources to proper directory for example src/main/java</module1.sonar.sources>
<!-- similiar for other 2 projects -->
That way all junit reports will be used per module but it will be listed in single project with modules. That way you will be able to see reports per module and per whole single project.
It's a good practise to check results after adding every single module. In case of failure simply check error in console and fix the problem.
I am able to achieve Integration test coverage using sonar with Jococo plugin.
To run the Sonar in local, i was facing the issue with SCM error in sonar.
Every time it was failing in the in sonar report creation.
For resolving the issue in local you need to disable the SCM configuration in sonar.
login in local sonar as Admin - admin/admin (default username/password)
Now under setting we have SCM tab - disable the SCM Senor and save the SCM Setting.
Now in Dashboard --> Configure widgets .Search "Integration Tests Coverage"
Now add widget into your Project Dashboard.
Follow the same configuration in your pom.xml as given in the link.
https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/java/code-coverage/combined%20ut-it/combined-ut-it-multimodule-maven-jacoco

Resources