How do I run FlyWay clean with Spring Boot? - spring

I'm using Spring Boot and FlyWay together. I added the FlyWay dependency to my Gradle build file like this:
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.postgresql:postgresql:9.4-1202-jdbc42")
compile("org.flywaydb:flyway-core")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
I also added a db/migrations folder with an initial migration file. The migration works as expected. But now I want to clean by using the gradle flywayClean task. However, when I run this, I get an error saying the task can't be found. Is there another way I'm supposed to do this with Spring Boot?

To run gradle flywayClean, you have to apply the plugin: 'org.flywaydb.flyway'
See http://flywaydb.org/getstarted/firststeps/gradle.html

Related

Is io.spring.dependency-management plugin required when using Spring Boot 2.3+ and Spring Cloud?

I'm using Gradle 6.6 to build my Spring Boot app. According to this post, the io.spring.dependency-management plugin is no longer needed since Gradle 5+ supports BOM files.
However, I receive the following error if I remove the plugin:
Could not run phased build action using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-6.6.1-bin.zip'.
Build file 'C:\my-app\build.gradle' line: 14
A problem occurred evaluating root project 'my-app'.
Could not find method dependencyManagement() for arguments [build_6e8ejdhnd2no2m9jw221sctmn3$_run_closure2#432e46e2] on root project 'my-app' of type org.gradle.api.Project.
Line 14 of my build.gradle file is referenced in the above error. Here are lines 14-18:
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Hoxton.SR8"
}
}
Is there another way to specify the required dependencies for Spring Cloud without using io.spring.dependency-management plugin?
dependencyManagement() is provided exclusively by the io.spring.dependency-management plugin. Which means you cannot use it if you don't use the plugin.
And in that case you have to use the gradle's platform capability.
In the post you linked there's an example of that.
To fix your build, remove the dependencyManagement part and add
implementation platform("org.springframework.cloud:spring-cloud-dependencies:Hoxton.SR8")
to your dependencies { }
Reference: https://docs.spring.io/dependency-management-plugin/docs/current/reference/html/#dependency-management-configuration-dsl

Usage of BootJar instead of BootRepackage in Gradle as part of Spring Boot Migration from 1..5.x to 2.x

I am working on Spring Boot migration from 1.5.12 to 2.1.14. We are using Gradle as a build tool, so as part of Spring Boot migration we had to change
Gradle from 3.x to 4.x and trying to update the build.gradle as required. In Spring Boot 2.x migration we have to change the following task in build.gradle
task msnServiceBoot(type: BootRepackage, dependsOn:msnJar) {
println " Executing MsnServiceBoot task"
mainClassName = 'com.msn.service.MsnApplication'
customConfiguration = "cloudconfigexclusion"
withJarTask = msnJar
}
In the above code we have to update BootRepackage to BootJar as per the latest Spring documentation.
The error, I'm getting after changing from BootRepackage to BootJar is customConfiguration is unknown property.
May I know how to make customConfiguration for Spring Boot 2.x with gradle 4.x

Convert gradle multi project to springboot fat jar application

I had a http servlet application which was a multi project gradle build, where my project was a contain gradle HttpServlet project and it depends on the other two gradle java projects. I deployed all the 3 jars in the tomcat webapps/Web-INF/lib directory and run it.
Now there is a requirement that I have to convert my application as a spring boot application and instead of 3 separate jars I have to create a fat jar which I should run it.
I don’t have much experience with grade and spring boot. I was wondering how can I create a fat jar from the multi gradle project.?
I converted my http servlet project to a spring boot project but I am confused that how I will refer the other gradle projects in the springboot project and create a single fat jar? Please see the directory structure of the projects
Rootrepository
- Springboot project
-src….
- OtherGardleProject1
- Src…
- OtherGardleProject2
- Src…
Can someone please share some pointer?
You could use a top-level settings.gradle file that includes the main app and the libraries
Rootrepository
- settings.gradle
- Springboot project
- build.gradle
-src….
- OtherGardleProject1
- Src…
- OtherGardleProject2
- Src…
The settings.gradle looks like this:
include: ':Springboot project', ':OtherGardleProject1', ':OtherGardleProject2'
Then in the build.gradle of the Springboot project module you add the dependencies to the libraries
plugins {
id 'org.springframework.boot' version '2.0.3.RELEASE'
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
...
dependencies {
compile project(':OtherGardleProject1')
compile project(':OtherGardleProject2')
...
}
After you build the project, the jar in Sprinboot project/build/libs folder should contain the classes of the app and the other two modules as jar files.
Hope it helps.

How to use JPA metamodel with gradle, intellij IDEA?

I am using java 8, spring boot 2.0.0, spring-data-jpa(spring-boot-starter-data-jpa), gradle, intellij. I've been trying to use JPA Metamodel, but having difficulty on finding how to configure.
Metamodels for Entity classes aren't just generated.
I guessed it would be simple, but now it seems that can be wrong. How can I use it?
JDK11 / Gradle 5.0 / Hibernate 5.3.7.Final
sourceSets.main.java.srcDirs += "${buildDir}/generated"
compileJava {
options.annotationProcessorGeneratedSourcesDirectory = file("${buildDir}/generated")
}
dependencies {
annotationProcessor("javax.xml.bind:jaxb-api")
annotationProcessor("org.hibernate:hibernate-jpamodelgen")
}
Generated Metamodel classes will be generated at 'build/generated'
If you are using JDK8 or Hibernate 5.4+, annotationProcessor("javax.xml.bind:jaxb-api") may unnecessary.
I did this the other day using the scalified metamodel gradle plugin (https://plugins.gradle.org/plugin/com.scalified.plugins.gradle.metamodel). I'm using Spring Boot 2.0.5, but I don't see why it wouldn't work the same with Spring Boot 2.0.0. I'm using Gradle 4.8.1 as well.
Below is an excerpt of my build.gradle.
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath (
"org.springframework.boot:spring-boot-gradle-plugin:2.0.0",
"gradle.plugin.com.scalified.plugins.gradle:metamodel:0.0.1");
}
}
apply plugin: "com.scalified.plugins.gradle.metamodel"
// The plugin will default to the latest version of Hibernate if this is not specified
metamodel {
hibernateVersion = '5.2.14.Final' // For Spring Boot 2.0.0
hibernateVersion = '5.2.17.Final' // For Spring Boot 2.0.5
}
This builds the metamodal files under src/generated and they can be used in your code. I had to also change an IntelliJ setting because IntelliJ's Build Automatically excludes some Gradle tasks that could be long running. See Automatically run Gradle task in project build with IntelliJ IDEA and https://youtrack.jetbrains.com/issue/IDEA-175165 for more details.
This setting I changed to overcome this is: Preferences->Build/Execution/Deployment->Gradle->Runner->Delegate IDE build/run actions to Gradle. An alternative would be to run the metamodelCompile gradle task manually as needed. That would lessen the time to rebuild by a little if you aren't frequently change your entities.

QueryDSL error duplicate class

I am using spring boot with query dsl to generate query classes for JPA objects
using the
plugin: "com.ewerk.gradle.plugins.querydsl"
The gradle compileQueryDsl task works fine.
When I run the gradle compileJava task
I see the Q classes being generated and then I get the duplicate class exception
In other plugins I have seen
options.compilerArgs = ['-proc:none',
helps Solve this issue.
Any suggestions to make this work.
Thanks
Try doing a 'gradle clean' first...
(I resolved a similar problem using maven doing a 'mvn clean package' instead of 'mvn package')

Resources