Liquibase changelog not running in spring boot - spring

I´m trying to run a springboot api and configure the database using liquibase.
The problem here is I followed all steps described in several tutorial but the changelog is never executed.
The code:
Gradle config:
group = 'com.strixtools'
version = '0.0.1-SNAPSHOT'
description = """Strix Tools"""
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.1.1.RELEASE"
classpath "gradle.plugin.com.palantir.gradle.docker:gradle-docker:0.20.1"
}
}
group = 'strixtools'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.palantir.docker'
bootJar {
baseName = 'gs-spring-boot-docker'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
configurations.all {
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
compile ('org.springframework.boot:spring-boot-starter:2.1.1.RELEASE')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version:'2.1.1.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version:'2.1.1.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version:'2.1.1.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version:'2.1.1.RELEASE'
compile group: 'org.springframework.security.oauth.boot', name: 'spring-security-oauth2-autoconfigure', version: '2.1.1.RELEASE'
compile group: 'org.apache.commons', name: 'commons-lang3', version:'3.4'
compile group: 'io.jsonwebtoken', name: 'jjwt', version:'0.9.0'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version:'2.6.5'
compile group: 'org.liquibase', name: 'liquibase-core'
compile group: 'com.h2database', name: 'h2', version:'1.4.196'
runtime group: 'org.postgresql', name: 'postgresql'
testCompile(group: 'org.springframework.boot', name: 'spring-boot-starter-test', version:'2.1.1.RELEASE')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-log4j2', version:'2.1.1.RELEASE'
}
task stage {
dependsOn build
}
task unpack(type: Copy) {
dependsOn bootJar
from(zipTree(tasks.bootJar.outputs.files.singleFile))
into("build/dependency")
}
docker {
name "${project.group}/${bootJar.baseName}"
copySpec.from(tasks.unpack.outputs).into("dependency")
buildArgs(['DEPENDENCY': "dependency"])
}
aplication.yml
strix-api:
host: https://aaa.com
client: asdasdasfasdf
secret: afadsfsdaf
user: afdadsfsadf
pass: afadsfsdafsdaf
---
spring:
profiles: local
datasource:
url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
username: sa
password:
liquibase:
change-log: classpath:db/changelog-master.xml
enabled: true
drop-first: true
jpa:
hibernate:
ddl-auto: none
show-sql: true
h2:
console:
enabled: true
and my SpringAplication class
#SpringBootApplication
public class StrixToolsApplication {
public static void main(String[] args) {
SpringApplication.run(StrixToolsApplication.class, args);
}
//TODO: we should move this to another side
#Bean(name = "messageSource")
public ReloadableResourceBundleMessageSource messageSource() {
ReloadableResourceBundleMessageSource messageBundle = new ReloadableResourceBundleMessageSource();
messageBundle.setBasename("classpath:messages/messages");
messageBundle.setDefaultEncoding("UTF-8");
return messageBundle;
}
#Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
}
The problem is liquibase is never executing. If I change the changelog name to anthing else it doesn't even throws an error.
Thanks for your help
Regards

In my case the problem was that I had a dependency declared for the gradle plugin, like so
liquibaseRuntime("org.liquibase:liquibase-core:3.8.1")
but not for liquibase at runtime, like so
runtimeOnly("org.liquibase:liquibase-core:3.8.1")

Maybe you are missing the right version of liquibase. Try with 2.0.1.
Here you have a small sample: (you can refactor the notation that you are using for versions and groups).
apply plugin: 'liquibase'
plugins {
id 'io.spring.dependency-management' version '1.0.5.RELEASE'
id 'org.liquibase.gradle' version '2.0.1'
}
ependencies {
implementation('org.springframework.boot:spring-boot-starter-actuator')
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.boot:spring-boot-starter-security')
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-validation')
implementation('org.liquibase:liquibase-core')
runtime 'mysql:mysql-connector-java'
liquibaseRuntime group: 'org.liquibase', name: 'liquibase-core', version: liquibaseCoreVersion
liquibaseRuntime group: 'org.liquibase', name: 'liquibase-groovy-dsl', version: liquibaseGroovyDslVersion
liquibaseRuntime 'mysql:mysql-connector-java'
}
liquibase {
activities {
main {
changeLogFile 'src/main/resources/db/liquibase-changelog.xml'
url 'jdbc:mysql://' + System.env.DATABASE_HOST + ':' + System.env.DATABASE_PORT + '/' + System.env.DATABASE_NAME + '?useSSL=false'
username System.env.DATABASE_USER
password System.env.DATABASE_PASSWORD
driver 'com.mysql.jdbc.Driver'
}
}
}

Related

Unable to run gradle program in command line

gradle test
Task :compileJava FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':compileJava'.
Could not resolve all dependencies for configuration ':detachedConfiguration1'.
Could not resolve org.springframework.boot:spring-boot-dependencies:2.2.7.RELEASE.
Required by:
project :
> Could not resolve org.springframework.boot:spring-boot-dependencies:2.2.7.RELEASE.
> Could not get resource 'https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-dependencies/2.2.7.RELEASE/spring-boot-dependencies-2.2.7.
RELEASE.pom'.
> Could not HEAD 'https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-dependencies/2.2.7.RELEASE/spring-boot-dependencies-2.2.7.RELEA
SE.pom'.
> repo.maven.apache.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
buildscript {
repositories {
maven {
url "https://rb-artifactory.bosch.com/artifactory/gradle-plugins-remote/"
credentials {
username "***"
password "***"
}
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.7.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "io.spring.dependency-management"
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
apply plugin: 'jacoco'
apply plugin: 'application'
jacocoTestReport{
reports{
xml.enabled true
csv.enabled true
html.enabled true
}
}
// This comes out to package + '.' + mainClassName
mainClassName = 'com.bosch.shop.ShopAuthentication'
repositories {
mavenCentral()
/* maven {
credentials {
username "EED1COB"
password "AP28P2xA2dB6pCNDcbrxx7uVuNo"
}
url "https://rb-artifactory.bosch.com/artifactory/gradle-mvn-remote/"
}*/
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
configurations {
providedRuntime
}
bootRun {
// allows ./gradlew bootRun -Dspring.profiles.active=dev
systemProperties System.properties
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web"){
exclude group: 'org.apache.tomcat'
}
implementation( "mysql:mysql-connector-java:5.1.28" )
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation('org.springframework.boot:spring-boot-starter-data-mongodb')
implementation("io.springfox:springfox-swagger2:2.6.1")
//implementation group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
implementation("io.springfox:springfox-swagger-ui:2.6.1")
//implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
implementation("com.google.code.gson:gson:2.8.2")
implementation("com.ocpsoft:ocpsoft-pretty-time:1.0.7")
implementation('org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2')
implementation ('org.json:json:20180130')
implementation("com.jayway.jsonpath:json-path:2.0.0")
implementation("com.mashape.unirest:unirest-java:1.4.9")
implementation("io.jsonwebtoken:jjwt:0.5.1")
implementation platform('org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE')
implementation 'org.springframework.boot:spring-boot-starter-web'
//implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.10.2'
//overridden-
//implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.8.0-beta2'
implementation group: 'com.google.guava', name: 'guava', version: '27.1-jre'
implementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '9.0.37'
implementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-websocket', version: '9.0.37'
implementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-el', version: '9.0.37'
implementation("com.sun.jersey:jersey-client:1.9.1")
implementation group: 'com.zaxxer', name: 'HikariCP', version: '3.2.0'
implementation group: 'org.locationtech.spatial4j', name: 'spatial4j', version: '0.7'
testImplementation('org.springframework.boot:spring-boot-starter-test')
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
testImplementation("junit:junit:4.12")
testImplementation group: 'org.mockito', name: 'mockito-core', version: '2.23.0'
implementation group: 'net.bytebuddy', name: 'byte-buddy', version: '1.9.7'
implementation group: 'net.bytebuddy', name: 'byte-buddy-agent', version: '1.9.7'
// https://mvnrepository.com/artifact/com.azure/azure-core
implementation group: 'com.azure', name: 'azure-core', version: '1.22.0'
// https://mvnrepository.com/artifact/com.azure/azure-messaging-servicebus
implementation group: 'com.azure', name: 'azure-messaging-servicebus', version: '7.4.2'
implementation group: 'io.projectreactor', name: 'reactor-core', version: '3.4.12'
implementation group: 'com.azure', name: 'azure-core-amqp', version: '2.3.4'
implementation group: 'org.mongodb', name: 'mongo-java-driver', version: '3.12.10'
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'org.apache.logging.log4j') {
details.useVersion '2.15.0'
}
}
}

Gradle Multi Module Project: Apply module dependency to all subprojects except for itself

My application is a Gradle Multi Module Project, consisting of multiple services with one service-common module.
I´ve pulled all dependencies that all modules have in common out into the root build.gradle, and I also want to include the service-common module in all subprojects, which in theory works, but I´m getting a circular dependency issue because it is included in itself.
apply plugin: 'java'
group = 'com.myapplication'
ext {
set('springCloudVersion', "2.2.0.RELEASE")
set('springBootVersion', "2.2.2.RELEASE")
}
allprojects {
repositories {
jcenter()
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
}
buildscript {
ext {
springBootVersion = "2.2.2.RELEASE"
}
repositories {
maven { url 'https://repo.spring.io/plugins-snapshot' }
jcenter()
mavenCentral()
}
dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:1.0.7.BUILD-SNAPSHOT'
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
subprojects {
version = '1.0'
apply plugin: 'org.springframework.boot'
apply plugin: "io.spring.dependency-management"
apply plugin: 'java'
ext {
springCloudVersion = "2.2.0.RELEASE"
springBootVersion = "2.2.2.RELEASE"
}
test {
useJUnitPlatform()
}
repositories {
mavenCentral()
jcenter()
maven { url 'https://repo.spring.io/milestone' }
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter', version: "${springBootVersion}"
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: "${springBootVersion}"
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: "${springBootVersion}"
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: "${springBootVersion}"
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: "${springBootVersion}"
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: "${springBootVersion}"
compile group: 'org.springframework.boot', name: 'spring-boot-starter-logging', version: "${springBootVersion}"
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter', version: "${springCloudVersion}"
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-kubernetes', version: '1.1.1.RELEASE'
compile group: 'io.micrometer', name: 'micrometer-registry-prometheus', version: '1.3.2'
compile group: 'com.github.piomin', name: 'logstash-logging-spring-boot-starter', version: '1.2.2.RELEASE'
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
compileOnly 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10'
testCompile group: 'com.h2database', name: 'h2', version: '1.4.200'
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.9'
testCompile group: 'org.springframework.cloud', name: 'spring-cloud-stream-test-support', version: "${springCloudVersion}"
implementation project(":service-common")
}
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
How can I exclude implementation project(":service-common") for the service-common module?
You can do something like:
subprojects {
dependencies {
if (!project.name == "service-common") {
implementation(project(":service-common"))
}
}
}

Configure application.properties in spring boot for public url in keycloak

I'm developing spring boot application (v 2.1.0) with keycloak to secure app (v 4.5.0).
I already configured keycloak security in gradle and application.properties.
However keycloak returns unauthorized (401 Error) even for urls which are not added to security constraints.
Gradle and application.properties file are provided following
Gradle
buildscript {
ext.kotlin_version = '1.3.11' // Required for Kotlin integration
ext.spring_boot_version = '2.1.0.RELEASE'
ext.keycloak_version = '4.5.0.Final'
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // Required for Kotlin integration
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version" // See https://kotlinlang.org/docs/reference/compiler-plugins.html#spring-support
classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version"
}
}
apply plugin: 'kotlin' // Required for Kotlin integration
apply plugin: "kotlin-spring" // https://kotlinlang.org/docs/reference/compiler-plugins.html#spring-support
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
jar {
baseName = 'gs-rest-service'
version = '0.1.0'
}
repositories {
jcenter()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile group: 'org.hibernate', name: 'hibernate-envers', version: '5.1.0.Final'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // Required for Kotlin integration
compile("org.jetbrains.kotlin:kotlin-reflect")
compile "org.springframework.boot:spring-boot-starter-web"
// compile 'org.springframework.boot:spring-boot-starter-security'
//KeyCloak
compile group: 'org.keycloak', name: 'keycloak-spring-boot-starter', version: '4.7.0.Final'
compile group: 'org.keycloak', name: 'keycloak-spring-boot-adapter', version: '4.7.0.Final'
compile "org.keycloak:keycloak-admin-client:$keycloak_version"
//RestEasy
// https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-client
compile group: 'org.jboss.resteasy', name: 'resteasy-client', version: '3.6.2.Final'
// https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs
compile group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.6.2.Final'
// https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jackson2-provider
compile group: 'org.jboss.resteasy', name: 'resteasy-jackson2-provider', version: '3.6.2.Final'
// //Oauth2
// // https://mvnrepository.com/artifact/org.springframework.security.oauth/spring-security-oauth2
// compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: '2.3.4.RELEASE'
// https://mvnrepository.com/artifact/org.springframework/spring-jdbc
compile group: 'org.springframework', name: 'spring-jdbc', version: '5.1.0.RELEASE'
// https://mvnrepository.com/artifact/org.postgresql/postgresql
compile group: 'org.postgresql', name: 'postgresql', version: '9.3-1100-jdbc41'
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Application.properties
#Server
server.port = 8090
# Database
spring.jpa.database=postgresql
#spring.datasource.platform
spring.jpa.show-sql=false
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/dbname
spring.datasource.username=postgres
spring.datasource.password=123
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
# new
keycloak.realm = realm
keycloak.auth-server-url = http://localhost:8080/auth
keycloak.ssl-required = external
keycloak.resource = client_id
keycloak.credentials.secret = client_secret
keycloak.realm-key=public_key
keycloak.security-constraints[0].auth-roles[0]=USER
keycloak.security-constraints[0].security-collections[0].patterns[0]=/user/*
keycloak.security-constraints[0].security-collections[0].patterns[1]=/createStudent
keycloak.security-constraints[0].auth-roles[1]=admin
keycloak.security-constraints[0].security-collections[1].patterns[0]=/createStudent2
keycloak.security-constraints[0].security-collections[1].patterns[1]=/createRole
keycloak.security-constraints[0].security-collections[1].patterns[2]=/roles
keycloak.security-constraints[0].security-collections[1].patterns[3]=/assignRole
keycloak.security-constraints[0].security-collections[1].patterns[4]=/users
I want login and main page of the app to be public
/login and /home
Thanks in advance!

Execute Cucumber Integration Tests with Spring Boot server running from Gradle plugin on Jenkins or any other CI server

I have a spring boot micro-services project built with Gradle.
I want to execute my cucumber integration tests on Jenkins or CI server just after code check-in. The build job on CI server gets triggered automatically after every code check-in. This job calls my gradle build.
I am able to execute the cucumber test cases as normal JUnit test case from my STS or eclipse and the embedded tomcat server gets started and after the cucumber test cases get executed on it, the server is stopped.
This is exactly what I want through gradle build:
How the cucumber integration tests get executed on a running spring boot embedded server by gradle.build ??
Current behavior is: when the gradle.build is called on CI server then the cucumber integration tests are just getting called with no target spring boot server.
Expected behavior: After gradle.build is called on CI server, the cucumber tests should get executed on the running spring boot embedded server and should get stop by itself after the cucumber test cases are executed.
NOTE: I have created a special cucumber-test profile for it in the project and have its own configuration file
My gradle.build looks like:
buildscript {
ext {
springBootVersion = '1.4.2.RELEASE'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
manifest {
attributes 'Main-Class': 'com.pa.omas.Main'
}
baseName = 'omas'
version = ''
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
maven { url "http://smartbearsoftware.com/repository/maven2" }
}
sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration-test/java')
}
resources.srcDir file('src/integration-test/resources')
}
}
configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
cucumberRuntime {
extendsFrom testRuntime
}
}
task copyScripts(type: Copy) {
from("scripts")
into("build/libs")
}
task copyReports(type: Copy) {
from("reports")
into("build/libs/reports")
}
task integrationTest(type: Test) {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
outputs.upToDateWhen { false }
}
check.dependsOn integrationTest
integrationTest.mustRunAfter test
tasks.withType(Test) {
reports.html.destination = file("${reporting.baseDir}/${name}")
}
bootRun {
args = ["--spring.profiles.active=cucumber-test"]
}
task cucumber(){
dependsOn assemble, compileTestJava
doLast {
javaexec {
main = "cucumber.api.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['-p', 'pretty', '--monochrome', '-p', 'html:reports/cucumber/cucumber-html-reports', '-p', 'junit:reports/cucumber-junit/cucumber-junit-report.xml',
'-p', 'html:reports/cucumber', '--glue', 'src/integration-test/java/com/pa/omas/cucumber', 'src/integration-test/resources']
}
copyReports
}
}
build {
dependsOn copyScripts
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.cloud:spring-cloud-starter-stream-kafka')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.projectlombok:lombok')
compile('org.springframework.boot:spring-boot-starter-web')
compile('ch.qos.logback:logback-classic')
compile('org.mariadb.jdbc:mariadb-java-client:1.5.4')
compile('org.hibernate:hibernate-java8')
compile 'com.puppycrawl.tools:checkstyle:8.3'
compile group: 'net.masterthought', name: 'cucumber-reporting', version: '3.11.0'
compile group: 'net.masterthought', name: 'maven-cucumber-reporting', version: '3.11.0'
compile group: 'com.zaxxer', name: 'HikariCP', version: '2.6.3'
compile('com.fasterxml.jackson.datatype:jackson-datatype-jsr310')
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.7.0'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.7.0'
testCompile('com.h2database:h2')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.mockito', name: 'mockito-all', version: '2.0.2-beta'
testCompile group: 'info.cukes', name: 'cucumber-junit', version: '1.2.5'
testCompile group: 'info.cukes', name: 'cucumber-spring', version: '1.2.5'
integrationTestCompile('com.h2database:h2')
integrationTestCompile('org.springframework.boot:spring-boot-starter-test')
integrationTestCompile 'info.cukes:cucumber-java:1.2.5'
integrationTestCompile 'junit:junit:4.12'
integrationTestCompile group: 'info.cukes', name: 'cucumber-junit', version: '1.2.5'
integrationTestCompile group: 'info.cukes', name: 'cucumber-spring', version: '1.2.5'
integrationTestCompile group: 'info.cukes', name: 'cucumber-java', version: '1.2.5'
integrationTestCompile group: 'info.cukes', name: 'cucumber-core', version: '1.2.5'
integrationTestCompile group: 'info.cukes', name: 'cucumber-html', version: '0.2.6'
integrationTestCompile group: 'info.cukes', name: 'cucumber-jvm-deps', version: '1.0.5'
integrationTestCompile group: 'info.cukes', name: 'gherkin', version: '2.12.2'
integrationTestCompile group: 'io.cucumber', name: 'gherkin', version: '5.0.0'
integrationTestCompile group: 'info.cukes', name: 'cucumber-java8', version: '1.2.5'
integrationTestCompile group: 'org.webjars.npm', name: 'gherkin', version: '4.1.3'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Camden.SR3"
}
}
My project structure looks like:
StepsDefinitionAnnotations
CucumberTest
Thanks very much !!
So finally, I found the solution to this issue.
The cucumber cli main class was unable to find the testRuntime in which the stepsDefinition file was located. Therefore, it was simply calling the cucumber test cases but not executing them.
All I did is included the sourceSets for main & test in the gradle file, linke below:
sourceSets {
main {
java {
srcDirs = ["src/main/java"]
}
}
test {
java {
srcDirs = ["src/test/"]
}
}
}
And it worked fine for me.
Thanks Anyways. Hope this will help others as well !!

ClassCastException with Spring-Websocket because of Tomcat ServerContainer

While trying to connect to Spring Websocket with SockJS, I am getting an error
org.springframework.web.util.NestedServletException: Request processing failed;
nested exception is org.springframework.web.socket.sockjs.SockJsException:
Uncaught failure in SockJS request, uri=http://localhost:8083//subscribe/info/771/nay07fet/websocket;
nested exception is org.springframework.web.socket.sockjs.SockJsTransportFailureException:
WebSocket handshake failure; nested exception is java.lang.ClassCastException:
org.eclipse.jetty.websocket.jsr356.server.ServerContainer cannot be cast
to org.apache.tomcat.websocket.server.WsServerContainer
From online I figured out that I shall disable Tomcat in Classpath to overcome it, but no matter how I try, I can not get rid of Tomcat.
How I can reliably exclude tomcat from any project? Note that I found it in several places.
My current Dependency tree is here: http://pastebin.com/pH1iQejd
and it contains some tomcat. I need to get rid of everything that might cause that type confusion.
Here's my gradle.build (I tried some exlcudes but without success):
group 'com.company'
if (!hasProperty("buildNumber")) {
version "1.0.0-SNAPSHOT"
} else {
version "1.0.${buildNumber}-SNAPSHOT"
}
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE")
classpath("gradle.plugin.com.boxfuse.client:flyway-release:4.0.1")
classpath fileTree(dir: 'libs', include: '*.jar')
classpath fileTree(dir: 'src/main/resources/db/migration', include: '*.sql')
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2"
}
}
dependencies {
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
exclude module: 'spring-boot-starter-logging'
}
compile("org.springframework.boot:spring-boot-starter-jetty") {
exclude module: "spring-boot-starter-tomcat"
exclude module: 'spring-boot-starter-logging'
}
// end::jetty[]
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-starter-data-jpa"){
exclude module: "spring-boot-starter-tomcat"
exclude module: 'spring-boot-starter-logging'
}
compile("org.springframework.boot:spring-boot-starter-data-rest")
compile("org.springframework.boot:spring-boot-starter-websocket")
// http://mvnrepository.com/artifact/org.springframework.security/spring-security-core
compile group: 'org.springframework.security', name: 'spring-security-core', version: '4.1.0.RELEASE'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'
compile group: 'com.google.code.gson', name: 'gson', version: '2.5'
compile group: 'com.rabbitmq', name: 'amqp-client', version: '3.5.6'
compile group: 'commons-configuration', name: 'commons-configuration', version: '1.9'
compile group: 'com.google.guava', name: 'guava', version: '18.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.5'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.5'
compile("org.springframework:spring-messaging")
compile 'org.springframework.amqp:spring-rabbit:1.5.5.RELEASE'
compile("com.h2database:h2")
compile 'org.quartz-scheduler:quartz:2.2.1'
compile group: 'joda-time', name: 'joda-time', version: '2.3'
//compile("com.npspot:jtransit-light:1.0.6")
compile("io.fastjson:boon:0.33")
compile fileTree(dir: 'libs', include: '*.jar')
// end::actuator[]
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile("org.springframework.boot:spring-boot-starter-test")
}
configurations {
compile.exclude module: "spring-boot-starter-tomcat"
compile.exclude module: 'spring-boot-starter-logging'
runtime.exclude module: "spring-boot-starter-tomcat"
runtime.exclude module: 'spring-boot-starter-logging'
}
test {
reports {
junitXml.enabled = true
html.enabled = false
}
}
springBoot {
executable = true
}
I was facing this problem as well. I solved it by adding the exclude clause to the websocket dependency, i.e.:
compile("org.springframework.boot:spring-boot-starter-websocket") {
exclude module: "spring-boot-starter-tomcat"
}
After this, I realized it wasn't necessary to have the exclusion on all the other ones; it's only necessary on starter-web and starter-websocket.

Resources