I am building Cassandra datastax 4.14 with Spring Boot and gradle 7.6
Gradle file:
plugins {
id 'java'
id 'org.springframework.boot' version "2.3.5.RELEASE"
id 'io.spring.dependency-management' version "1.0.9.RELEASE"
id "io.freefair.lombok" version "6.6.3"
}
dependencies {
...
implementation 'io.github.lognet:grpc-spring-boot-starter:4.5.4'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
// Cassandra
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
annotationProcessor group: 'com.datastax.oss', name: 'java-driver-mapper-processor', version: cassandraSdkVersion
implementation "com.datastax.oss:java-driver-mapper-runtime:4.14.0"
implementation "com.datastax.oss:java-driver-core:4.14.0"
implementation "com.datastax.oss:java-driver-query-builder:4.14.0"
compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
// Force native protocol.
implementation "com.datastax.oss:native-protocol:1.5.1"
...
}
Simple Example of my code
import com.datastax.oss.driver.api.mapper.annotations.Mapper;
import com.datastax.oss.driver.api.mapper.annotations.DaoFactory;
import com.datastax.oss.driver.api.mapper.annotations.DaoKeyspace;
import com.datastax.oss.driver.api.mapper.annotations.DaoTable;
import com.datastax.oss.driver.api.mapper.annotations.Dao;
import com.datastax.oss.driver.api.core.CqlSession;
@Mapper
public interface CassandraMapper {
static CassandraMapper build(CqlSession session) {
return new CassandraMapper(session).build();
}
@DaoFactory
ExampleDao exampleDao(@DaoKeyspace String keyspace, @DaoTable String table);
}
Entity
import lombok.Builder;
import lombok.Data;
import com.datastax.oss.driver.api.mapper.annotations.Entity;
import com.datastax.oss.driver.api.mapper.annotations.PartitionKey;
@Data
@Builder
@Entity
public class EntityObject {
@PartitionKey private long id;
private Long version;
}
When I try to run gradle compileJava, I get the error:
java.lang.NoClassDefFoundError: com/datastax/oss/driver/api/mapper/entity/naming/GetterStyle
I've tried configuring annotationProcessor, I've read the docs at https://docs.datastax.com/en/developer/java-driver/4.14/manual/mapper/config/lombok/ and https://github.com/DataStax-Examples/object-mapper-jvm/tree/master/lombok, but I can't seem to find any issues.
It looks like spring dependency management was downgrading my mapper library.
I added annotationProcessor "com.datastax.oss:java-driver-mapper-runtime:4.14.0"
to my gradle file to force the correct version, and it builds now.