I'm working on a multi-module project which contains a service and an integration-tests module.
In the service module there is a service for some reset password functionality, based on Spring greenhouse which is using a template file which is expected to be loaded on initialization. While trying to solve this issue I changed slightly the initialization of the class based on the loaded file and moved it to xml configuration:
<bean id="resetPasswordMailMessageConverter" class="com.myapp.service.reset.ResetPasswordMailMessageConverter">
<constructor-arg name="resource">
<value>classpath*:**/spring/reset-password.st</value>
</constructor-arg>
</bean>
The service works fine once deployed and used in tomcat but there are issues when integration tests are executed : Unable to read template resource class path resource [classpath*:**/spring/reset-password.st]
I placed that file in both places serviceModule/META-INF/spring/ and integrationTestsModule/META-INF/spring/ but still it can't be found.
I placed some code both in service and in integration tests where I export the result of ClassLoader.getSystemResources("META-INF") and noticed that in both cases the integrationModule/target/test-classes/META-INF and the .m2/repository/../serviceModule.jar!META-INF are included in the exported path and the file is contained inside both META-INF/spring/ but not found.
I tried also keeping the file in the same package with the converter and initializing converter's resource as new ClassPathResource("reset-password.st", getClass().getClassLoader()) or new ClassPathResource("reset-password.st") but didn't work.
The structure of the project is mainModule->[mainSubmoduleA->[serviceModule, integrationTestsModule, etc], mainSubmoduleB[other modules]]
Any idea?
There's a basic layout of the project structure
Parts of the pom files:
main:
...........
<groupId>com.myapp</groupId>
<artifactId>mainModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
.............
<modules>
<module>mainSubmoduleA</module>
<module>mainSubmoduleB</module>
</modules>
mainSubmoduleA:
..............
<parent>
<groupId>com.myapp</groupId>
<artifactId>mainModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
.........
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp.mainsuba</groupId>
<artifactId>mainSubmoduleA</artifactId>
<packaging>pom</packaging>
<name>mainSubmoduleA</name>
..........
<modules>
<module>subModuleAA</module>
</modules>
...............
subModuleAA:
<parent>
<groupId>com.myapp.mainsuba</groupId>
<artifactId>mainSubmoduleA</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp.mainsuba.subaa</groupId>
<artifactId>subModuleAA</artifactId>
<packaging>pom</packaging>
<name>subModuleAA</name>
..........
<modules>
<module>service</module>
<module>web</module>
<module>integration</module>
</modules>
service:
<parent>
<groupId>com.myapp.mainsuba.subaa</groupId>
<artifactId>subModuleAA</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp.mainsuba.service</groupId>
<artifactId>service</artifactId>
<packaging>jar</packaging>
<name>service</name>
web:
<parent>
<groupId>com.myapp.mainsuba.subaa</groupId>
<artifactId>subModuleAA</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp.mainsuba.web</groupId>
<artifactId>web</artifactId>
<packaging>war</packaging>
<name>web</name>
integration:
<parent>
<groupId>com.myapp.mainsuba.subaa</groupId>
<artifactId>subModuleAA</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>integration</artifactId>
<packaging>jar</packaging>
<name>integration</name>
<description>Integration Tests</description>
Chris,
try setting the resource value without any ant-style wildcard matchers. I.e.:
<value>META-INF/spring/reset-password.st</value>
More info on wildcard restrictions can be found here: Other notes relating to wildcards
Related
I have 3 projects Parent,Child,SubChild.
Project Parent pom is as follows:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
</parent>
<groupId>mu.parent</groupId>
<artifactId>parent-system</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
....
Project Child pom is defined below and its Parent is defined follows:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>mu.parent</groupId>
<artifactId>parent-system</artifactId>
<version>1.0</version>
</parent>
<groupId>mu.dummy.child</groupId>
<artifactId>child-backend</artifactId>
<name>child-backend</name>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>subChild-app</module>
</modules>
...
Now subChild pom is as follows and the child is defined as parent for subChild :
<parent>
<groupId>mu.dummy.child</groupId>
<artifactId>child-backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>mu.dummy.subchild</groupId>
<artifactId>subchild-backend</artifactId>
<name>subchild-backend</name>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>org.project.test</groupId>
<artifactId>project</artifactId>
<version></version> --version of parent-system???
</dependency>
</dependencies>
Is it possible to get version of parent-system(1.0) in subchild-backend please without hardcoding it?
You can use CI-friendly versions and write ${revision} for the versions, setting this property in the main pom (from which you build everything).
You need to use the flatten Maven plugin, though, to get proper POMs in the repository.
I asked a similar question a while back and determined that tthe groovy-maven-plugin works for this. See this answer.
I have a test project which is based on a parent project. This parent is build beforehand and is available on local artifactory server. The parent project is not available locally and this should stay this way.
As you see I am not using the relativePath element.
Still, when running "mvn clean install -U" I get an error about missing parent.
[ERROR] Non-resolvable parent POM for com.test.example:test:0.0.1-SNAPSHOT: Could not find artifact com.test:projects-parent:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM # line 6, column 10 -> [Help 2]
The test project pom.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.example</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test</name>
<parent>
<groupId>com.test</groupId>
<artifactId>projects-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencies>
...
</dependencies>
<build>
...
</build>
</project>
Here is the parent pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<groupId>com.test</groupId>
<artifactId>projects-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
</project>
According to this, the default value for <relativePath> is ../pom.xml, so Maven will look locally first.
If you want to force the lookup to occur in your repository manager, use this trick:
<parent>
<groupId>com.test</groupId>
<artifactId>projects-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath/> <!— This forces a lookup against the repo —>
</parent>
error message:
The POM for rc:common:jar:1.0 is missing, no dependency information available
parent pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>rc</groupId>
<artifactId>springboot-multiple-maven-modules</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>rest</module>
<module>common</module>
</modules>
rest pom.xml
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>rc</groupId>
<artifactId>springboot-multiple-maven-modules</artifactId>
<version>1.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>rest</artifactId>
<name>zeyo rest</name>
<!--<version>1.0</version>-->
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>rc</groupId>
<artifactId>common</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
common pom.xml
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>rc</groupId>
<artifactId>springboot-multiple-maven-modules</artifactId>
<version>1.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>common</artifactId>
<name>common</name>
<version>1.0</version>
<packaging>jar</packaging>
Once you have a dependency called rc -> rest -> common.
Why is this happening?
That simply says that common project not yet built and we started rest.
First run the maven install on parent project so that 'common' project will be built as well.
spring-boot:run : does not build the dependent jars.
Hope this helps.
I have like 10 maven projects(and behind them Jenkins jobs) which have quite the same configuration. They all have a parent, call it ancient.
<parent>
<groupId>com.example</groupId>
<artifactId>ancient</artifactId>
<version>1.0.0</version>
</parent>
<groupId>com.example</groupId>
<artifactId>child_10</artifactId>
<version>1.0.0</version>
<properties >
<reports.to.keep>20</reports.to.keep>
</properties>
Now I don't want to add the properties which are the same for all those members, so I created a parent for all my 10 children:
<parent>
<groupId>com.example</groupId>
<artifactId>ancient</artifactId>
<version>1.0.0</version>
</parent>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
<properties >
<reports.to.keep>20</reports.to.keep>
</properties>
I adapted the children to point to that one.
<parent>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
</parent>
Thats for the concept. Now I got the problem that I can not deploy my parent to my repository, as it always like wants to build whats configured in the ancient.
I am quite new to Maven: is this even possible? Or is there an other way to manage multiple maven projects with inheritance?
Problem is that ancient is configured so that I can not use deploy or deploy-file as they are configured to deploy something else. I also want them configured like that for my child-projects.
I have to create a Spring Boot project that will have a web interactive part and a batch part a,d both with the same DB (so they share the DAOs and Services), I wonder how to do it and I guess that the best approach is to create a Multi Module Project
something like this
<modules>
<module>core</module>
<module>batchApplication</module>
<module>userApplication</module>
</modules>
But, do I have to create more than 1 pom and project ??? or I can do it in the same pom ?
You will need a parent pom which has the spring-boot as a parent, then a directory and with pom for each child project. Your parent pom will be like:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</parent>
<groupId>com.barclaycard</groupId>
<artifactId>bc-alu</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Barclaycard Address LookUp</name>
<modules>
<module>bc-alu-ref</module>
<module>bc-alu-web</module>
</modules>
</project>
See here for mutil module project https://maven.apache.org/guides/mini/guide-multiple-modules.html