usually when I start a project the structure in the package explorer is something like this:
src/main/java
|- org.companyname.myproject
|- repositories
| |- ClassA.java
| |- ClassB.java
|- services
| |- userservice
| | |- ClassC.java
| |- otherservice
| | |- ClassD.java
so in the package explorer I can quickly expand and collapse all the relevant packages.
However recently when I import projects as a gradle project this structure is converted to:
src/main/java
|- org.companyname.myproject.repositories
| |- ClassA.java
| |- ClassB.java
|- org.companyname.myproject.services.userservice
| |- ClassC.java
|- org.companyname.myproject.services.otherservice
| |- ClassD.java
I know this is only esthetically but for me it's so obnoxious and unreadable. Any tips on how to restore the original structure view?
If I remember correctly I didn't have this issue earlier when I imported gradle projects.
Thank you very much.
Your view package presentation setting needs to change. Just change it from flat to the hierarchical section shown below.
Related
In our Spring boot Java project we are having flyway migration scripts. Below is our project structure,
Project
|
|
+-- src
| |
| +-- resources
|
+-- db.migration
|
+--V1_0_db_script.sql (scheme_one)
+-- test
| |
| +-- resources
| |
| +-- db
| |
| +-- data-test
| | |
| | +--V1_0_test_db_script.sql (scheme_one)
| +-- data-sql
| | |
| | +--V1_0_sql_db_script.sql (scheme_second)
| |
+-- application-test.yml
Now, here is my application-test.yml structure.
Flyway :
enabled: true
schemas: scheme_one
locations:
- classpath: /db/data-sql
- classpath: /db/migration
- classpath: /db/data-test
Now, what is needed here is that while running test cases, it should execute data-sql directory first it means V1_0_sql_db_script.sql should execute first then db.migration and then data-test directory. But its not executing in the order which defined in location (My assumption is from top to bottom, even I tried bottom to top).
Now what's happening, it always first executing db.migration which is located under main src package. But I want to execute data-sql directory scripts first anyhow while test cases are started to run as there are some queries which is needed for other scripts. One more thing, there are actually two different schemes used. I have defined in brackets.
Kindly suggest if flyway have any property to define order or any other feedback will be appreciated.
I have the following Maven project structure with Junit and Cucumber:
| root project
| Module 1
| src
| main
| test
| java
| tests // where all step definitions from Module 1 are stored
| resources
| features // feature files from Module 1
| Module 2
| src
| main
| test
| java
| tests // where all step definitions from Module 2 are stored
| resources
| features // feature files from Module 2
I want to reuse the steps from Module 1 in Module 2. Is it possible to import step definitions from Module 1 to Module 2 to reuse them there?
What you are already doing is kind of correct approach. You need to consider the following:
Since your Step Defs are in test the are not transitively take part in module2 class path
Make also sure there that the step defs in module1 are in a proper package relationships to your module2: your runner class in module2 is in the same package or above than your feature file which is in the same package or above than your step definition class
Make sure that module2 has module1 as a dependency
So to remediate point 1 in your example you need to move your step definition in module1 from test to main
This is the structure of my project.
The parent contains no code.
module child1 is a spring boot application.
modules child2, child3 are jars libraries.
child1 depends on child2 and child3
parent
| build.gradle
| settings.gradle
| [no code]
child1
| build.gradle
| src/
| main/
| java/
| resources/
| application.properties
| test/
| java/
| resources/
| application.properties
child2
| build.gradle
| src/
| main/
| java/
| test/
| java/
child3
| build.gradle
| src/
| main/
| java/
| test/
| java/
I have a property called "datapath" that I would like to inject into classes in each of the modules.
There are two possible values for "datapath", one for tests and one for production.
I set the production value in
child1/src/main/resources/application.properties
and the test value in
child1/src/test/resources/application.properties
I have tried creating configuration classes and specifying PropertySource.
But the result has been that though child1 picks up the correct application properties in both test and main, spring does not find them in other modules.
Can you propose a strategy for me to implement this?
In particular:
The tests in the child1 are annotated SpringBootTest but preferably child2 and child3 should not depend on spring boot (just spring framework for autowiring)
I would like to be able to use the #Value annotation on configuration classes in the child modules.
How do I direct spring to resolve these properties from the application.properties in the child1 module, using the one in src/test/resources for tests and the one in src/main/resources for production?
As I have chosen a very "classical" structure, I would like to be able to achieve this with as few as possible moving parts. In particular I would prefer not to have to specify paths explicitly in annotations.
I assume that in child2 and child3 you need application.properties only for test. Then in test you can use #TestPropertySource where you can point relative path to properties file in child1 or add datapath explicitly:
#TestPropertySource(properties = { "datapath=value" })
public class Child2Test {
I'm using swagger with Spring Boot and the UI does not shows the controllers.
My project looks like: I have a few gradle modules in root project.
There are two of them for REST:
documentation (in this module I have package *.documentation and there I have a few interfaces with swagger annotations)
rest (in this module I have package *.controller and there each controller implements documentation interface from module documentation)
When I'm trying to run swagger-ui there is no resources on the UI.
BUT! when I move my controllers into documentation module then everything works fine or when I move interfaces with swagger annotations to rest module. Problem is only when I use two modules, one for swagger annotations and one to implement those interfaces.
What should I do to make it works with two modules? I tried also ComponentScan annotation in my SwaggerConfig class(this class is also in documentation module) but it does not works too.
My project structure:
|-- Project
| |-- app
| |-- src/main/java
| |-- mypackage
| |-- App.java
| |-- documentation
| |-- src/main/java
| |-- mypackage
| |-- config
| |-- SwaggerConfig.java
| |-- documentation
| |-- ProductSwaggerInterface.java
| |-- rest
| |-- src/main/java
| |-- mypackage
| |-- controller
| |-- ProductController.java
In 'app' module I just run the SpringBoot app, in 'documentation' module I have interfaces with swagger annotations and in module 'rest' I implementing those interfaces in my controller.
I'm working on a spring application that contains submodules, roughly looking like the following:
project
|-- module1
||-- src
|| -- main
|| |-- java
|| -- resources
|| |-- null
|| -- pom.xml
Module 2:
|-- module2
| |-- src
| | -- main
| | |-- java
| | -- resources
| | -- spring-dao.xml
| -- pom.xml
-- pom.xml
now,I'm using Juit4 to test module1,while I have to offer spring-dao.xml in module1,like this:
#ContextConfiguration({"classpath*:spring/spring-dao.xml"})
But the spring configuration file(spring-dao.xml) is in module2, and module2 is dependent on module1. That causes I can't put module2.jar into module1 via the pom.xml of module1 as it causes a module cycle.
How can I test module1?
I'm not sure I understand completely, but here's how I read it:
Module 1 has a dependency on Module 2, and Module 2 has a dependency on Module 1.
The short answer is you cannot do this. The idea behind modules is to segregate unrelated code. I often do this with generated code, keeping that in a separate module. The generated code shouldn't have any dependencies on my main application, but my main application depends on the generated code.
I can think of a couple solutions:
If the two modules are that heavily dependent on each other, they should be refactored into a single module. This seems like the best approach, based on what you've described.
If this still isn't desireable, make a third module to hold common dependencies between the two projects.