Gradle build cannot find method ResponseEntity.of(object)

513 views Asked by At

I'm converting my working maven spring-boot project to gradle spring-boot. This is how my dependencies look like:

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'

// https://mvnrepository.com/artifact/javax.validation/validation-api
compile group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
// https://mvnrepository.com/artifact/org.springframework/spring-web
compile group: 'org.springframework', name: 'spring-web', version: '5.0.1.RELEASE'

implementation 'org.mapstruct:mapstruct:1.3.0.Final'
implementation 'org.postgresql:postgresql:42.2.6'
runtimeOnly 'com.h2database:h2:1.4.199'
testImplementation 'junit:junit:4.10'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.1.8.RELEASE'
// https://mvnrepository.com/artifact/org.jboss.logging/jboss-logging
compile group: 'org.jboss.logging', name: 'jboss-logging', version: '3.4.1.Final'
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'

testCompileOnly 'org.projectlombok:lombok:1.18.12'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'

Some how in thiscode

ResponseEntity<ProductDTO> update(@Validated @PathVariable Long id, @Validated @RequestBody 
 ProductDTO productDTO) {
 Optional<ProductDTO> updated = productService.update(id, productDTO);
 return ResponseEntity.of(updated);
}

ResponseEntity.of() is not found by when I run gradlew clean build.

    return ResponseEntity.of(updated);
                             ^
symbol:   method of(Optional<CategoryDTO>)
    location: class ResponseEntity
    6 errors
    1 warning
Task :compileJava FAILED

The class ResponseEntity is available but the of method. I'm using the latest version of spring-starter-web so I'm not sure why did it happened.

Any help would be appreciated.

1

There are 1 answers

0
Andiana On

Found it: The problem is the version of spring-web is a bit old. I need to use a newer version

compile group: 'org.springframework', name: 'spring-web', version: '5.2.6.RELEASE'