Skip to content

Commit 2c1a742

Browse files
authored
Fix build under the latest JDKs by migrating on the spotless plugin (temporalio#390)
1 parent 2d8a392 commit 2c1a742

File tree

11 files changed

+40
-27
lines changed

11 files changed

+40
-27
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ This repository contains sample Workflow applications that demonstrate various c
2222
- [IDE Integration](#ide-integration)
2323
- [IntelliJ](#intellij)
2424

25+
## Requirements
26+
27+
- Java 1.8+ for build and runtime
28+
- Java 11+ for development and contribution
29+
2530
## How to use
2631

2732
1. Clone this repository:

build.gradle

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@
22

33
plugins {
44
id 'org.cadixdev.licenser' version '0.6.1'
5-
id 'com.github.sherter.google-java-format' version '0.9'
65
id "net.ltgt.errorprone" version "3.0.1"
6+
id 'com.diffplug.spotless' version '6.11.0' apply false
77
}
88

99
apply plugin: 'java'
10-
apply plugin: 'com.github.sherter.google-java-format'
11-
12-
googleJavaFormat {
13-
toolVersion (JavaVersion.current().isJava11Compatible() ? '1.15.0' : '1.7')
14-
}
1510

1611
java {
1712
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -26,7 +21,7 @@ repositories {
2621
}
2722

2823
dependencies {
29-
implementation(platform("com.fasterxml.jackson:jackson-bom:2.14.0"))
24+
implementation(platform("com.fasterxml.jackson:jackson-bom:2.14.1"))
3025
implementation(platform("io.opentelemetry:opentelemetry-bom:1.20.1"))
3126
implementation(platform("org.junit:junit-bom:5.9.1"))
3227

@@ -62,7 +57,7 @@ dependencies {
6257
testImplementation("io.temporal:temporal-testing:1.17.0")
6358

6459
testImplementation "junit:junit:4.13.2"
65-
testImplementation group: 'org.mockito', name: 'mockito-core', version: '4.8.1'
60+
testImplementation group: 'org.mockito', name: 'mockito-core', version: '4.9.0'
6661
testImplementation group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.9'
6762

6863
testImplementation "org.junit.jupiter:junit-jupiter-api"
@@ -79,10 +74,6 @@ dependencies {
7974
}
8075
}
8176

82-
compileJava {
83-
dependsOn 'googleJavaFormat'
84-
}
85-
8677
task execute(type: JavaExec) {
8778
main = findProperty("mainClass") ?: ""
8879
classpath = sourceSets.main.runtimeClasspath
@@ -97,3 +88,18 @@ license {
9788
exclude '**/*.json'
9889
exclude '**/*.yml'
9990
}
91+
92+
if (JavaVersion.current().isJava11Compatible()) {
93+
// Code should be formatted using the latest googleJavaFormat, but it doesn't support Java <11 since version 1.8
94+
apply plugin: 'com.diffplug.spotless'
95+
96+
spotless {
97+
java {
98+
target 'src/*/java/**/*.java'
99+
targetExclude '**/.idea/**'
100+
googleJavaFormat('1.15.0')
101+
}
102+
}
103+
104+
compileJava.dependsOn 'spotlessApply'
105+
}

docker/buildkite/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM eclipse-temurin:8-focal
1+
FROM eclipse-temurin:11-focal
22

33
# Git is needed in order to update the dls submodule
44
RUN apt-get update && apt-get install -y wget protobuf-compiler git

src/main/java/io/temporal/samples/batch/iterator/IteratorBatchWorkflowImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public final class IteratorBatchWorkflowImpl implements IteratorBatchWorkflow {
5252
@Override
5353
public int processBatch(int pageSize, int offset) {
5454
// Loads a page of records
55-
List<Record> records = recordLoader.getRecords(pageSize, offset);
55+
List<SingleRecord> records = recordLoader.getRecords(pageSize, offset);
5656
// Starts a child per record asynchrnously.
5757
List<Promise<Void>> results = new ArrayList<>(records.size());
58-
for (Record record : records) {
58+
for (SingleRecord record : records) {
5959
// Uses human friendly child id.
6060
String childId = Workflow.getInfo().getWorkflowId() + "/" + record.getId();
6161
RecordProcessorWorkflow processor =

src/main/java/io/temporal/samples/batch/iterator/RecordLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ public interface RecordLoader {
3939
* @param pageSize maximum number of records to return.
4040
* @return empty list if no more records to process.
4141
*/
42-
List<Record> getRecords(int pageSize, int offset);
42+
List<SingleRecord> getRecords(int pageSize, int offset);
4343
}

src/main/java/io/temporal/samples/batch/iterator/RecordLoaderImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public final class RecordLoaderImpl implements RecordLoader {
3030
public static final int PAGE_COUNT = 5;
3131

3232
@Override
33-
public List<Record> getRecords(int pageSize, int offset) {
34-
List<Record> records = new ArrayList<>(pageSize);
33+
public List<SingleRecord> getRecords(int pageSize, int offset) {
34+
List<SingleRecord> records = new ArrayList<>(pageSize);
3535
if (offset < pageSize * PAGE_COUNT) {
3636
for (int i = 0; i < pageSize; i++) {
37-
records.add(new Record(offset + i));
37+
records.add(new SingleRecord(offset + i));
3838
}
3939
}
4040
return records;

src/main/java/io/temporal/samples/batch/iterator/RecordProcessorWorkflow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ public interface RecordProcessorWorkflow {
2828

2929
/** Processes a single record */
3030
@WorkflowMethod
31-
void processRecord(Record r);
31+
void processRecord(SingleRecord r);
3232
}

src/main/java/io/temporal/samples/batch/iterator/RecordProcessorWorkflowImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class RecordProcessorWorkflowImpl implements RecordProcessorWorkflow {
3030
private final Random random = Workflow.newRandom();
3131

3232
@Override
33-
public void processRecord(Record r) {
33+
public void processRecord(SingleRecord r) {
3434
// Simulate some processing
3535
Workflow.sleep(Duration.ofSeconds(random.nextInt(30)));
3636
log.info("Processed " + r);

src/main/java/io/temporal/samples/batch/iterator/Record.java renamed to src/main/java/io/temporal/samples/batch/iterator/SingleRecord.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@
2020
package io.temporal.samples.batch.iterator;
2121

2222
/** Record to process. A real application would add a use case specific data. */
23-
public class Record {
23+
public class SingleRecord {
2424
private int id;
2525

26-
public Record(int id) {
26+
public SingleRecord(int id) {
2727
this.id = id;
2828
}
2929

3030
/** JSON deserializer needs it */
31-
public Record() {}
31+
public SingleRecord() {}
3232

3333
public int getId() {
3434
return id;
3535
}
3636

3737
@Override
3838
public String toString() {
39-
return "Record{" + "id=" + id + '}';
39+
return "SingleRecord{" + "id=" + id + '}';
4040
}
4141
}

src/main/java/io/temporal/samples/batch/slidingwindow/SlidingWindowBatchWorkflowImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public final class SlidingWindowBatchWorkflowImpl implements SlidingWindowBatchW
5151
/** Count of completed record processing child workflows. */
5252
private int progress;
5353

54-
/** @return number of processed records */
54+
/**
55+
* @return number of processed records
56+
*/
5557
@Override
5658
public int processBatch(ProcessBatchInput input) {
5759
WorkflowInfo info = Workflow.getInfo();

0 commit comments

Comments
 (0)