Customize Dependency Versions in Spring boot - spring

I want to use Quartz 2 dependency with spring 1.5.2.RELEASE
There I want to override the parent spring pom dependency for the quartz dependency only.
I tried to do this :
<properties>
<quartz.version>2.3.0</quartz.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
</dependencies>
Error:
Project build error: 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-quartz:jar is missing.

Related

Adding spring integration is causing conflict in Spring boot

I have following maven
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
..
..
// custome library
</dependencies>
When I add spring integration dependency
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-file</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
i am getting following error:
Consider marking one of the beans as #Primary, updating the consumer to accept multiple beans, or using #Qualifier to identify the bean that should be

Maven Build Fails when "spring-boot-starter-web-services" starter is used with 2.1.13.RELEASE of Spring Boot Version

I am not able to build spring boot application when spring web service starter is used with 2.1.13.RELEASE version of spring boot. This is coming due to spring-ws-core:jar:3.0.8.RELEASE.
Exception while building application : It comes during default test case execution .
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.ws.config.annotation.WsConfigurationSupport] from ClassLoader [sun.misc.Launcher$AppClassLoader#42a57993]
Caused by: java.lang.NoClassDefFoundError: org/springframework/xml/transform/TransformerObjectSupport
Caused by: java.lang.ClassNotFoundException: org.springframework.xml.transform.TransformerObjectSupport
Warning :
The POM for org.springframework.ws:spring-ws-core:jar:3.0.8.RELEASE is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
Pom File :
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.13.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Although there are many ways to solve the issue, the best option is :-
Use a newer version of spring-boot-starter-parent
e.g.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
</parent>
issue solved.

Maven doesn't run unit tests in a multi-module project with Spring Boot

Maven supports multi-module applications by having the child modules point to the parent module, but Spring Boot wants it's parent to be
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
According to the Spring docs I can still do this (use a maven parent-child relationship) if I add dependency management like this:
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
instead of the Spring Boot parent.
I've done this, but now my unit tests don't run when I run mvn from the command line. The unit tests still work from Intellij, but something in the new parent-child / changes is confusing mvn and keeping it from running tests.
Here's a pom.xml from a module that no longer runs its tests:
<project xmlns=...>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>abcd</groupId>
<artifactId>abcd.parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>entities</artifactId>
<name>entities</name>
<description>Entities and Repositories</description>
<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
This module is a library module that does not contain a #SpringBootApplication but the tests ran before converting to the maven parent-child structure.
Edit:
This project has both junit 4 and junit-jupiter-api 5.5.2 in its dependencies. When using org.junit.jupiter.api.Test (5.5.2) no tests run. When using org.junit.Test (4.12) the test runs but the Autowired repository doesn't get injected (null). (The Autowired repository is in another module.)
Spring doesn't handle dependencies correctly when using a normal maven child-parent structure.

Spring-boot(maven) actuator,devtools not working

I'm a newbie to spring-boot. Trying to create a simple web application using spring-boot maven. Basic static page display using dependency spring-boot-starter-web worked fine. When I included spring-boot-devtools and spring-boot-starter-actuator in pom.xml it is giving build error Re-run Maven using the -X switch to enable full debug logging.
I tried including spring-webmvc dependency in pom file, still the result is same.
<?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.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.test</groupId>
<artifactId>jspTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>jspTest</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
I downloaded this project from spring.io (SPRING INITIALIZR website). Build project is getting failed.
<scope>runtime</scope> of spring-boot-devtools suppose not to be runtime. In fact according to the doc -
Developer tools are automatically disabled when running a fully
packaged application. If your application is launched from java -jar
or if it is started from a special classloader, then it is considered
a “production application”. Flagging the dependency as optional in
Maven or using a customdevelopmentOnly configuration in Gradle (as
shown above) is a best practice that prevents devtools from being
transitively applied to other modules that use your project.
So, change the dependency as below -
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
you can update your pom.xml and change the version number to any previous stable version.It worked for me.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>**xyz_previous_.RELEASE**</version>
<relativePath/> <!-- lookup parent from repository -->

How to create spring boot cloud maven based application where parent project is not org.springframework.cloud

I want to create spring cloud project where parent project is my common project and all other modules depends on this custom parent project and not on "org.springframework.cloud" as parent project .
I do not want to add this in my parent pom
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Brixton.BUILD-SNAPSHOT</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
In simple words I do not want to add spring cloud as parent in maven module hierarchy.
If you generate project using spring initializer Spring Initializer then you get
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Remove the parent section and bring in Spring Boot dependencies management as a bom.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.4.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
You have to add <dependencyManagement> section in pom.xml file. Looks like,
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>

Resources