MapStruct throws exception when try to build project - spring-boot

There is springboot application with gradle and try to convert one object to another using MapStruct, but there is exception in compile time
I added sctruct dependencies in build.gradle by instruction in bottom
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}
group = 'my.bot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'com.github.briandilley.jsonrpc4j:jsonrpc4j:1.6'
implementation 'javax.jws:javax.jws-api:1.1'
implementation 'org.mapstruct:mapstruct:1.5.3.Final'
implementation 'org.mapstruct:mapstruct-processor:1.5.3.Final'
}
tasks.named('test') {
useJUnitPlatform()
}
tasks.withType(JavaCompile) {
options.compilerArgs = [
'-Amapstruct.suppressGeneratorTimestamp=true'
]
}
My interface look like this
#Mapper
public interface DeviceAgentMessageMapper {
#Mapping(source = "gamma", target = "message")
AgentMessage toAgentMessage(Device device);
}
But when try to start application or call build gradle job, there is error message:
The following options were not recognized by any processor: '[mapstruct.suppressGeneratorTimestamp]'
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at ConstructorResolver.java:800
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException at DefaultListableBeanFactory.java:1801

Related

Redis OM Spring - Gradle issue: not generating meta classes "com.redis.om.skeleton.models.Person$

I am trying to use gradle for this project https://redis.io/docs/stack/get-started/tutorials/stack-spring/. My build.gradle is this one:
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.2'
id 'io.spring.dependency-management' version '1.1.0'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation "com.redis.om:redis-om-spring:0.6.4"
implementation "io.springfox:springfox-boot-starter:3.0.0"
implementation "io.springfox:springfox-swagger-ui:3.0.0"
}
test {
useJUnitPlatform()
}
I am getting the following err while build this project:
error: cannot find symbol
import com.redis.om.skeleton.models.Person$;
It seems META model classes are not being generated by gradle. I am using Intellij Community edition with java 17.
Any help would be appreciate.
I had to add the following to my build.gradle and it solved my issue:
annotationProcessor("com.redis.om:redis-om-spring:0.6.4")

How to fix Could not find or load main class in Spring boot gradle.build?

Im new in gradle and i receive and error about my main class is Could not find or load main class i tried to fix it but doest work.
plugins {
id 'org.springframework.boot' version '2.6.9'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.notification'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2021.0.3")
}
dependencies {
implementation 'io.awspring.cloud:spring-cloud-aws-context:2.3.1'
implementation 'io.awspring.cloud:spring-cloud-aws-autoconfigure:2.3.1'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-stream'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
tasks.named('test') {
useJUnitPlatform()
}
springBoot {
mainClass = 'com.notification.NotificationServiceApplication'
}
Error
Error: Could not find or load main class com.notifcation.NotificationServiceApplication
Caused by: java.lang.ClassNotFoundException: com.notifcation.NotificationServiceApplication
Disregard this post question. I just restart my IDE

Could not resolve Lombok for library

Library Gradle project can't find Lombok dependency.
When I delete Lombok from dependencies all compiled successfully. Perhaps Lombock required some special settings for use in the library?
FAILURE: Build failed with an exception.
Throw the error:
What went wrong: Execution failed for task ':lib:compileJava'.
Could not resolve all files for configuration ':lib:compileClasspath'.
Could not find org.projectlombok:lombok:.
Required by:
project :lib
shared/settings.gradle
rootProject.name = 'shared'
include('lib')
shared/lib/build.gradle
plugins {
id 'java-library'
}
group = 'com.openhelp'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.jetbrains:annotations:20.1.0'
compileOnly 'org.projectlombok:lombok'
testImplementation 'junit:junit:4.13.2'
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:30.1.1-jre'
annotationProcessor 'org.projectlombok:lombok'
}
tasks.named('test') {
useJUnitPlatform()
}
Where mistake?

Intellij Idea Jpa Repository suggestion is not working

I created a Spring Boot project on Intellij Idea
here is my configuration
Spring Boot version: id 'org.springframework.boot' version '2.6.7'
Intellij Idea Build #IU-221.5080.210, built on April 12, 2022
here is my build.gradle file
plugins {
id 'org.springframework.boot' version '2.6.7'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'net.ltgt.apt' version '0.21'
}
group = 'io.project'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = "17"
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springdoc:springdoc-openapi-ui:1.6.8'
implementation 'org.hibernate.validator:hibernate-validator:7.0.4.Final'
implementation 'org.mapstruct:mapstruct:1.4.2.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
targetCompatibility = JavaVersion.VERSION_17
and here is one of my classes that extends JpaRepository
#Repository
public interface CommentRepository extends JpaRepository<CommentEntity, Long> {
List<CommentEntity> findAllByPostId(Long postId);
}
when I try to write my methods name I do not get suggestions from JpaRepository
any idea why this is happening?

Use main Gradle project to define all dependencies versions

I want to create one main Gradle project which hosts all project dependencies:
Main Gradle project:
plugins {
id 'org.springframework.boot' version '2.6.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'maven-publish'
}
group = 'com.parent.dependencies'
version = '0.0.1'
sourceCompatibility = '11'
ext {
set('springCloudVersion', "2021.0.1")
artifactory_contextUrl = "http://192.168.1.112/repository"
}
repositories {
mavenCentral()
maven {
url "${artifactory_contextUrl}/plugins-release"
allowInsecureProtocol = true
}
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.boot:spring-boot-starter-validation'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.threeten:threetenbp:1.5.1'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
// Lombok
compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
testCompileOnly 'org.projectlombok:lombok:1.18.22'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
// Swagger
implementation group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'
implementation 'org.springframework.boot:spring-boot-starter-hateoas:2.6.3'
implementation group: 'com.netflix.hystrix', name: 'hystrix-core', version: '1.5.18'
implementation group: 'org.springframework.security', name: 'spring-security-core', version: '5.6.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
resolutionStrategy {
cacheDynamicVersionsFor 0, "seconds"
cacheChangingModulesFor 0, "seconds"
}
}
bootJar {
enabled = false
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
mavenLocal()
}
}
test {
useJUnitPlatform()
}
Sub project which will read all dependencies versions from parent Gradle project:
plugins {
id 'org.springframework.boot' version '2.6.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'maven-publish'
}
group = 'com.child'
version = '0.0.1'
sourceCompatibility = '11'
ext {
artifactory_contextUrl = "http://192.168.1.112/repository"
}
repositories {
mavenCentral()
maven {
url "${artifactory_contextUrl}/plugins-release"
allowInsecureProtocol = true
}
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.boot:spring-boot-starter-validation'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.threeten:threetenbp'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
// Swagger
implementation 'io.springfox:springfox-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
implementation 'com.netflix.hystrix:hystrix-core'
implementation 'org.springframework.security:spring-security-core'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}
dependencyManagement {
imports {
mavenBom "com.parent:com-parent-dependencies:0.0.1"
}
}
bootJar {
enabled = false
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
mavenLocal()
}
}
test {
useJUnitPlatform()
}
When I try to compile the child project I get error:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not find org.threeten:threetenbp:.
Required by:
project :
> Could not find io.springfox:springfox-boot-starter:.
Required by:
project :
> Could not find com.netflix.hystrix:hystrix-core:.
Required by:
project :
Do you know how I can define properly the parent Gradle project with all dependencies versions and use the child project without defining dependencies versions?
There’s a relatively new Gradle feature called “version catalogs”. With those you can centrally declare dependencies that you’d like to share between multiple projects of your build (or even between different builds).
In your concrete example, you’d add something like the following to your settings.gradle file:
dependencyResolutionManagement {
versionCatalogs {
libs {
library('spring-cloud-bom', 'org.springframework.cloud:spring-cloud-dependencies:2021.0.1')
library('spring-cloud-starter', 'org.springframework.cloud', 'spring-cloud-starter-netflix-eureka-client').withoutVersion()
library('spring-boot-starter-validation', 'org.springframework.boot', 'spring-boot-starter-validation').withoutVersion()
library('spring-boot-starter-test', 'org.springframework.boot', 'spring-boot-starter-test').withoutVersion()
library('threetenbp', 'org.threeten:threetenbp:1.5.1')
library('spring-boot-starter-actuator', 'org.springframework.boot', 'spring-boot-starter-actuator').withoutVersion()
library('lombok', 'org.projectlombok:lombok:1.18.22')
library('springfox-boot-starter', 'io.springfox:springfox-boot-starter:3.0.0')
library('spring-boot-starter-hateoas', 'org.springframework.boot:spring-boot-starter-hateoas:2.6.3')
library('hysterix-core', 'com.netflix.hystrix:hystrix-core:1.5.18')
library('spring-security-core', 'org.springframework.security:spring-security-core:5.6.1')
library('junit-jupiter-api', 'org.junit.jupiter:junit-jupiter-api:5.8.2')
library('junit-jupiter-engine', 'org.junit.jupiter:junit-jupiter-engine:5.8.2')
}
}
}
Then, in both build.gradle files, you’d replace your dependencies blocks with the following:
dependencies {
implementation libs.spring.cloud.starter
implementation libs.spring.boot.starter.validation
testImplementation libs.spring.boot.starter.test
implementation libs.threetenbp
implementation libs.spring.boot.starter.actuator
// Lombok
compileOnly libs.lombok
annotationProcessor libs.lombok
testCompileOnly libs.lombok
testAnnotationProcessor libs.lombok
// Swagger
implementation libs.springfox.boot.starter
implementation libs.spring.boot.starter.hateoas
implementation libs.hysterix.core
implementation libs.spring.security.core
testImplementation libs.junit.jupiter.api
testRuntimeOnly libs.junit.jupiter.engine
}
As you’re using a Maven BOM for Spring, you’ll also have to use the following updated dependencyManagement block in all projects:
dependencyManagement {
imports {
mavenBom libs.spring.cloud.bom.get().toString()
}
resolutionStrategy {
cacheDynamicVersionsFor 0, "seconds"
cacheChangingModulesFor 0, "seconds"
}
}
That should be it. I could successfully test your sample build configurations with my updates at least on Gradle 7.4.

Resources