Skip to content

Commit 505c0b1

Browse files
committed
JAVA-2800: Exclude SLF4J from mapper-processor dependencies
1 parent df4de3c commit 505c0b1

4 files changed

Lines changed: 25 additions & 14 deletions

File tree

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### 4.8.0 (in progress)
66

7+
- [bug] JAVA-2800: Exclude SLF4J from mapper-processor dependencies
78
- [new feature] JAVA-2819: Add DriverConfigLoader.fromString
89
- [improvement] JAVA-2431: Set all occurrences when bound variables are used multiple times
910
- [improvement] JAVA-2829: Log protocol negotiation messages at DEBUG level

mapper-processor/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@
4040
<dependency>
4141
<groupId>com.datastax.oss</groupId>
4242
<artifactId>java-driver-mapper-runtime</artifactId>
43+
<exclusions>
44+
<!--
45+
Exclude the dependency to SLF4J, otherwise this causes a warning when the processor is
46+
configured with -processorpath, because no SLF4J backend is present (JAVA-2800).
47+
48+
Note however that some of the code generated by the processor does reference SLF4J types
49+
(see LoggingGenerator). In those cases we have to resort to ClassName.get(String, String)
50+
instead of using the SLF4J classes directly.
51+
-->
52+
<exclusion>
53+
<groupId>org.slf4j</groupId>
54+
<artifactId>slf4j-api</artifactId>
55+
</exclusion>
56+
</exclusions>
4357
</dependency>
4458
<dependency>
4559
<groupId>com.datastax.oss</groupId>

mapper-processor/src/main/java/com/datastax/oss/driver/internal/mapper/processor/DefaultProcessorContext.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package com.datastax.oss.driver.internal.mapper.processor;
1717

1818
import com.datastax.oss.driver.internal.core.context.DefaultDriverContext;
19-
import com.datastax.oss.driver.internal.core.util.concurrent.CycleDetector;
2019
import com.datastax.oss.driver.internal.core.util.concurrent.LazyReference;
2120
import com.datastax.oss.driver.internal.mapper.processor.dao.LoggingGenerator;
2221
import com.datastax.oss.driver.internal.mapper.processor.entity.DefaultEntityFactory;
@@ -29,14 +28,11 @@
2928
/** This follows the same principles as {@link DefaultDriverContext}. */
3029
public class DefaultProcessorContext implements ProcessorContext {
3130

32-
private final CycleDetector cycleDetector =
33-
new CycleDetector("Detected cycle in context initialization");
34-
3531
private final LazyReference<CodeGeneratorFactory> codeGeneratorFactoryRef =
36-
new LazyReference<>("codeGeneratorFactory", this::buildCodeGeneratorFactory, cycleDetector);
32+
new LazyReference<>(this::buildCodeGeneratorFactory);
3733

3834
private final LazyReference<EntityFactory> entityFactoryRef =
39-
new LazyReference<>("entityFactory", this::buildEntityFactory, cycleDetector);
35+
new LazyReference<>(this::buildEntityFactory);
4036

4137
private final DecoratedMessager messager;
4238
private final Types typeUtils;

mapper-processor/src/main/java/com/datastax/oss/driver/internal/mapper/processor/dao/LoggingGenerator.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@
2121
import com.squareup.javapoet.MethodSpec;
2222
import com.squareup.javapoet.TypeSpec;
2323
import javax.lang.model.element.Modifier;
24-
import org.slf4j.Logger;
25-
import org.slf4j.LoggerFactory;
2624

2725
public class LoggingGenerator {
26+
27+
// Reference these types by name to avoid a compile-time dependency to SFL4J
28+
private static final ClassName LOGGER_FACTORY_CLASS_NAME =
29+
ClassName.get("org.slf4j", "LoggerFactory");
30+
private static final ClassName LOGGER_CLASS_NAME = ClassName.get("org.slf4j", "Logger");
31+
2832
private final boolean logsEnabled;
2933

3034
public LoggingGenerator(boolean logsEnabled) {
@@ -45,12 +49,8 @@ public void addLoggerField(TypeSpec.Builder classBuilder, ClassName className) {
4549
if (logsEnabled) {
4650
classBuilder.addField(
4751
FieldSpec.builder(
48-
ClassName.get(Logger.class),
49-
"LOG",
50-
Modifier.PRIVATE,
51-
Modifier.FINAL,
52-
Modifier.STATIC)
53-
.initializer("$T.getLogger($T.class)", LoggerFactory.class, className)
52+
LOGGER_CLASS_NAME, "LOG", Modifier.PRIVATE, Modifier.FINAL, Modifier.STATIC)
53+
.initializer("$T.getLogger($T.class)", LOGGER_FACTORY_CLASS_NAME, className)
5454
.build());
5555
}
5656
}

0 commit comments

Comments
 (0)