Old Build File
buildscript {
ext {
springBootVersion = '2.3.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("net.sf.proguard:proguard-gradle:6.0.2")
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.2")
}
}
plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'java'
id 'jacoco'
}
apply plugin: 'org.sonarqube'
apply plugin: 'io.spring.dependency-management'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
String build_display_name = System.getenv("BUILD_DISPLAY_NAME")
String branch_name = System.getenv("BRANCH_NAME") ?: "local"
String workspace = System.getenv("WORKSPACE")
String cred_usr = System.getenv("CRED_USR")
String cred_psw = System.getenv("CRED_PSW")
jacocoTestReport {
reports {
xml.enabled true
}
}
sonarqube {
properties {
property 'sonar.projectKey', 'onc-devicemanager'
property 'sonar.projectName', 'onc-devicemanager'
property "sonar.branch.name", "${branch_name}"
property 'sonar.projectVersion', "${build_display_name}"
property "sonar.sources", "src/main/java"
property "sonar.java.binaries", "build/classes"
property "sonar.jacoco.reportPath", "build/jacoco/test.exec"
}
}
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
compileOnly {
extendsFrom annotationProcessor
}
all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
}
repositories {
mavenCentral()
maven {
credentials {
username "${cred_usr}"
password "${cred_psw}"
}
}
}
ext {
springKafkaVersion = '2.5.3.RELEASE'
commonsVersion='3.9'
jUnitVersion='4.13.1'
apachePoiVersion='4.1.2'
commonsVersion='3.10'
set('springCloudVersion', "Hoxton.SR5")
}
task printVersion {
doLast {
println project.version
}
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation("org.springframework.kafka:spring-kafka:$springKafkaVersion")
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.11.0'
compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.11.0'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
implementation("org.apache.poi:poi-ooxml:$apachePoiVersion")
compile 'org.springframework.retry:spring-retry'
compile("org.apache.commons:commons-lang3:$commonsVersion")
implementation("org.apache.logging.log4j:log4j-core:2.17.0")
implementation("org.apache.logging.log4j:log4j-api:2.17.0")
implementation("org.apache.logging.log4j:log4j-to-slf4j:2.17.0")
implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.17.0")
compileOnly("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")
testCompile("junit:junit:$jUnitVersion")
testCompile("commons-io:commons-io:2.8.0")
implementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.kafka:spring-kafka-test:$springKafkaVersion")
testCompile group: 'org.awaitility', name: 'awaitility', version: '3.1.6'
/* shedlock */
implementation group: 'net.javacrumbs.shedlock', name: 'shedlock-spring', version: '4.25.0'
implementation group: 'net.javacrumbs.shedlock', name: 'shedlock-provider-mongo', version: '4.25.0'
compile 'io.micrometer:micrometer-core:1.5.1'
compile 'io.micrometer:micrometer-registry-prometheus:1.5.1'
/* Logback Dependency */
compile('ch.qos.logback:logback-classic:1.2.3')
compile('ch.qos.logback.contrib:logback-json-classic:0.1.5')
compile('ch.qos.logback.contrib:logback-jackson:0.1.5')
testCompile('ch.qos.logback:logback-classic:1.2.3')
testCompile('ch.qos.logback.contrib:logback-jackson:0.1.5')
testCompile('ch.qos.logback.contrib:logback-json-classic:0.1.5')
testImplementation 'guru.nidi:graphviz-java:0.18.1'
testImplementation 'org.graalvm.js:js:20.0.0'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
def sourcePath = "src/main/resources"
def destinationPath = "build/resources/test/"
task deploy(type: Copy) {
from sourcePath
into destinationPath
include "fsm.yaml"
rename("fsm.yaml", "for_validation_fsm.yaml")
}
compileJava.dependsOn(deploy)
New Build File :
buildscript {
ext {
springBootVersion = '2.6.6'
}
repositories {
mavenCentral()
}
dependencies {
classpath("net.sf.proguard:proguard-gradle:6.0.2")
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.2")
}
}
plugins {
id 'org.springframework.boot' version '2.6.6'
id 'java'
id 'jacoco'
}
apply plugin: 'org.sonarqube'
apply plugin: 'io.spring.dependency-management'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
String build_display_name = System.getenv("BUILD_DISPLAY_NAME")
String branch_name = System.getenv("BRANCH_NAME") ?: "local"
String workspace = System.getenv("WORKSPACE")
jacocoTestReport {
reports {
xml.enabled true
}
}
sonarqube {
properties {
property 'sonar.projectKey', 'onc-devicemanager'
property 'sonar.projectName', 'onc-devicemanager'
property "sonar.branch.name", "${branch_name}"
property 'sonar.projectVersion', "${build_display_name}"
property "sonar.sources", "src/main/java"
property "sonar.java.binaries", "build/classes"
property "sonar.jacoco.reportPath", "build/jacoco/test.exec"
}
}
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
compileOnly {
extendsFrom annotationProcessor
}
all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
exclude group:'org.apache.logging.log4j', module:'log4j-slf4j-impl'
}
}
repositories {
mavenCentral()
maven {
allowInsecureProtocol = true
}
maven {
credentials {
username "${cred_usr}"
password "${cred_psw}"
}
allowInsecureProtocol = true
}
}
ext {
springKafkaVersion = '2.8.1'
commonsVersion='3.9'
jUnitVersion='4.13.2'
apachePoiVersion='4.1.2'
commonsVersion='3.10'
set('springCloudVersion', "2021.0.2")
}
task printVersion {
doLast {
println project.version
}
}
dependencies {
implementation("org.springframework.kafka:spring-kafka:$springKafkaVersion")
testImplementation ("org.springframework.kafka:spring-kafka-test:$springKafkaVersion") {
// needed if downgrading to Apache Kafka 2.8.1
exclude group: 'org.apache.zookeeper', module: 'zookeeper'
}
testImplementation "org.apache.kafka:kafka-clients:$springKafkaVersion:test"
testImplementation "org.apache.kafka:kafka_2.13:$springKafkaVersion:test"
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation("org.springframework.kafka:spring-kafka")
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.13.2'
implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.13.2'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
implementation("org.apache.poi:poi-ooxml:$apachePoiVersion")
implementation 'org.springframework.retry:spring-retry'
implementation("org.apache.commons:commons-lang3:$commonsVersion")
implementation("org.apache.logging.log4j:log4j-core:2.17.0")
implementation("org.apache.logging.log4j:log4j-api:2.17.0")
implementation("org.apache.logging.log4j:log4j-to-slf4j:2.17.0")
implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.17.0")
compileOnly("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")
testImplementation("junit:junit:$jUnitVersion")
testImplementation("commons-io:commons-io:2.8.0")
implementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.kafka:spring-kafka-test")
testImplementation group: 'org.awaitility', name: 'awaitility', version: '3.1.6'
/* shedlock */
implementation group: 'net.javacrumbs.shedlock', name: 'shedlock-spring', version: '4.25.0'
implementation group: 'net.javacrumbs.shedlock', name: 'shedlock-provider-mongo', version: '4.25.0'
implementation 'io.micrometer:micrometer-core:1.5.1'
implementation 'io.micrometer:micrometer-registry-prometheus:1.5.1'
/* Logback Dependency */
implementation('ch.qos.logback:logback-classic:1.2.3')
implementation('ch.qos.logback.contrib:logback-json-classic:0.1.5')
implementation('ch.qos.logback.contrib:logback-jackson:0.1.5')
testImplementation('ch.qos.logback:logback-classic:1.2.3')
testImplementation('ch.qos.logback.contrib:logback-jackson:0.1.5')
testImplementation('ch.qos.logback.contrib:logback-json-classic:0.1.5')
testImplementation 'guru.nidi:graphviz-java:0.18.1'
testImplementation 'org.graalvm.js:js:20.0.0'
}
jar {
enabled = false
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
def sourcePath = "src/main/resources"
def destinationPath = "build/resources/test/"
task deploy(type: Copy) {
from sourcePath
into destinationPath
include "fsm.yaml"
rename("fsm.yaml", "for_validation_fsm.yaml")
}
compileJava.dependsOn(deploy)
Junit File:
public class TestKafkaConfig {
@InjectMocks
KafkaConfiguration kafkaConfiguration;
@Before
public void setup() {
MockitoAnnotations.openMocks(this);
}
@Test
public void testKafkaInventoryConsumerFactory() {
ProducerFactory<String, NotificationSchemaBean> inventoryProducerFactory = kafkaConfiguration.notificationProducerFactory();
Assert.assertNotNull(inventoryProducerFactory);
}
@Test
public void testConsumerFactory() {
ConsumerFactory<String, String> consumerFactory = kafkaConfiguration.consumerFactory();
Assert.assertNotNull(consumerFactory);
}
@Test
public void testKafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<String, String> factory = kafkaConfiguration.kafkaListenerContainerFactory();
Assert.assertNotNull(factory);
}
}
ext {
springKafkaVersion = '2.5.3.RELEASE'
jUnitVersion='4.13.1'
apachePoiVersion='4.1.2'
commonsVersion='3.10'
set('springCloudVersion', "Hoxton.SR5")
}
The above s/w versions upgraded as below ,
ext {
springKafkaVersion = '2.8.6'
jUnitVersion='4.13.2'
apachePoiVersion='4.1.2'
commonsVersion='3.10'
set('springCloudVersion', "2021.0.2")
}
Stack Trace:
Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:1804
Caused by: java.lang.NoClassDefFoundError at DefaultMetricsProvider.java:126
Caused by: java.lang.ClassNotFoundException at BuiltinClassLoader.java:581
When i upgrade the spring boot version from 2.3.1.RELEASE to 2.6.6, Above 3 Junits are failing. Anyone has an idea?
CodePudding user response:
By removing the below dependencies issue got solved,
compile 'io.micrometer:micrometer-core:1.5.1'
compile 'io.micrometer:micrometer-registry-prometheus:1.5.1'